2013-05-01 2 views
2

저는 방금 발전기를 실험하기 시작했습니다. 내 생성 된 뷰 템플릿 중 하나, 난과 같이 render를 호출 할 :레일 : 생성기 내에서 렌더링 호출

(erb):1:in `template': undefined method `render' for #<Slim::Generators::ScaffoldGenerator:0x000000041b2a20> (NoMethodError) 

이 레일에서 render를 호출 정말 능력이 있습니다 :

index.js.slim 
    transition("#main", "<%= escape_javascript(render 'index') %>"); 

내가 발전기를 사용하려고 할 때이 오류가 발전기 내에서? 아니면 내가 잘못하고있는거야?

답변

1

Railscast 218 더 많은 내용이수록 :

The first thing to note is that because we’re using the template method, all of the erb tags in the code will be executed when the generator runs. If we want to include any erb in the generated file we’ll have to escape the percent sign at the beginning of each erb tag and we’ve done that for most of the erb code above.

을이 경우 :

transition("#main", "<%= escape_javascript(render 'index') %>"); 

이 될해야합니다

transition("#main", "<%%= escape_javascript(render 'index') %>"); 

이 필요한 모든이 ERB를 탈출하는 추가 %이었다.