2011-06-17 58 views
1

這是我new.js.erb調用渲染功能行如何傳遞一個變量來渲染?

$('.node_container').append("<%= escape_javascript(render(@care_point, :locals => {:care_map => @care_map}))%>"); 

給出錯誤信息:

ActionView::Template::Error (undefined local variable or method `care_map' 

我的部分_care_point.html.erb:

<%= link_to 'Delete', [care_map, care_point], :confirm => "Are you sure?", :method => :delete, :remote => true, :class => 'delete' %> 
+0

這是@care_map在你的控制器中定義的嗎? (我的意思是在format.js塊) – bor1s

+1

來傳遞'locals'變量,你必須使用'render:partial => ...'而不僅僅是'render @ var' – apneadiving

+0

@apneadiving - 把它放在一個答案中: ) – willcodejavaforfood

回答

1

要傳遞當地變量,您必須使用

render :partial => partial_name, :locals => { # all your vars here } 

而不單單是:

render @var 

見文件here,第3.4.4

+3

在Rails 3中,你實際上可以做到:'render partial_name,:local1 =>「thing」,:local2 =>「other」'等等,不需要':partial'或':locals'位;) – d11wtq

+0

@ d11wtq:對,感謝這些論文的細節:) – apneadiving

相關問題