Rails如何将集合传递给从* .js.erb文件呈现的局部视图

时间:2011-10-25 01:42:15

标签: ruby-on-rails

当我在update.js.erb的{​​{1}}中执行此操作时

RewardsController

但是日志说:

$('div#rewards_list').html("<%=
  escape_javascript(render :partial    => 'shared/rewards',
                           :collection => @rewards,
                           :as => reward,
                           :locals => { :user => @user }
                   )
%>");

在我的'更新'操作方法中:

ActionView::Template::Error (undefined local variable or method `reward' for
  #<#<Class:0xbb395d8>:0xbb3774c>):

1 个答案:

答案 0 :(得分:2)

:as选项应该是一个符号,而不是变量(尤其不是一个不存在的变量),也许你的意思是:

$('div#rewards_list').html("<%= escape_javascript(render :partial => 'shared/rewards', :collection => @rewards, :as => :reward, :locals => {:user => @user}) %>");

我刚刚将:as => reward更改为:as => :reward。有关详细信息,请参阅Layouts and Rendering in Rails指南。