当我在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>):
答案 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指南。