fly*_*llo 2 ruby-on-rails ruby-on-rails-3
我需要将两个实例变量传递给ajax请求用来更新用户显示的javascript文件.这就是我需要做的事情:
respond_to do |format|
if @post.save
format.js { @post @user_vote } # <-- right here
else
format.html { redirect_to :back, :alert => 'There was an error in removing the vote' }
end
end
Run Code Online (Sandbox Code Playgroud)
这是怎么做到的?
小智 7
如果使用js.erb文件,则无需传递实例变量.您可以直接放置rails标记并在js.erb文件中访问这些变量
例如:
在您的控制器刚刚放
format.js #instead of format.js { @post @user_vote }
Run Code Online (Sandbox Code Playgroud)
在js.erb文件中,您可以访问实例变量
$('#ele').html("<%= @post.name %>");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3632 次 |
| 最近记录: |