2017-09-28 13 views
1

Slim으로 작성된 템플릿이 있는데 루비와 함께 사용하고 싶지만 index.slim에이 오류가 있습니다.슬림 레일 변수

-content_panel_file = '_partials/content_panel_5' 
    -content_box_file = '_partials/content_box_2' 
    - menu_file = '_partials/menu_side' 
    = render '_partials/template' 
template.slim에서

:

.content-i 
     .content-box 
      == Slim::Template.new(content_box_file).render(Object.new, 'template_vars' => template_vars) 

하지만이 오류가 준 :

undefined local variable or method `content_box_file' for #<#<Class:0x00000003b28308>:0x00000003b685c0> 
Did you mean? content_for 

답변

1

이유는 당신의 content_box_file이 부분 파일에 존재하지 않는입니다, 당신은 노력하고 현재 "범위"에없는 로컬 변수에 액세스합니다.

은 렌더링 방식에서 로컬 하나로 content_box_file 변수를 전달하십시오 :

= render partial: '_partials/template', locals: { content_box_file: content_box_file } 

주 당신은 render partial: ...를 사용해야합니다.

전체 워크 플로우 : 당신의 응답을

# model/index.html.slim 
- content_box_file = 'app/views/_partials/content_box_2.slim' 
= render partial: '_partials/template', locals: { content_box_file: content_box_file } 

# _partials/_template.html.slim: 
- template_vars = 'Hallo' 
== Slim::Template.new(content_box_file).render(Object.new, template_vars: template_vars) 

# _partials/content_box_2.html.slim: 
== template_vars 
+0

thnx 내가 그 시도하지만 난 같은 오류 – mar

+0

있어 당신은 부분 @mar 사용'= 렌더링로 지정하지 않는 부분 : '...' ' . –