Passing instance variable to js.erb file (Rails 3 / jQuery)

こ雲淡風輕ζ 提交于 2019-12-04 06:40:31

You access the information in your *.js.erb-files just like in your *.html.erb-files, using @users or other instance variables declared in the controller:

$("#<%= @user.id %>_action").toggle();

there's an excellent gem called gon that might simplify and organize things quite a bit: https://github.com/gazay/gon/blob/master/README.md

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!