如何传递变量进行渲染?

时间:2011-06-17 14:05:53

标签: javascript ruby-on-rails ajax

这是我的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' %>

1 个答案:

答案 0 :(得分:1)

要传递locals变量,您必须使用

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

而不仅仅是:

render @var

请参阅文档here,段3.4.4