ajax – 使用link_to remote:true将参数传递给rails
发布时间:2020-12-16 02:52:36 所属栏目:百科 来源:网络整理
导读:所以我有一个包含多个消息的页面,每个消息都有一个链接,用于更改(精炼)该消息的RATING.当用户单击此链接时,我想要一个 AJAX调用,它会更新该消息的数据库中的相应列值.单击此链接时,不会发生任何明显的情况.应该没有页面刷新或重新加载. 我一直在尝试使用link
所以我有一个包含多个消息的页面,每个消息都有一个链接,用于更改(精炼)该消息的RATING.当用户单击此链接时,我想要一个
AJAX调用,它会更新该消息的数据库中的相应列值.单击此链接时,不会发生任何明显的情况.应该没有页面刷新或重新加载.
我一直在尝试使用link_to remote:true,但我似乎无法让它工作.在线文档在这个问题上相当不清楚,并且随着Rails 2和3之间的变化,一些事情如:不再支持. 到目前为止,我已经复制了我所拥有的内容,但我知道它甚至不会接近解决方案. 提前致谢! show.html.haml .status-bar = link_to "",{ action: :refine_result },remote: true profile_controller.rb ... def refine_result @refinement = ResultRefinement.new @refinement.profile_id = params[:profile_id] @refinement.message_id = params[:message_id] @refinement.save respond_to do |format| format.html { render nothing: true } format.js { render nothing: true } end end result_refinement.rb class ResultRefinement < ActiveRecord::Base attr_accessible :profile_id,:message_id,:new_rating,:deleted belongs_to :profile end 解决方法
您需要首先为ProfileController#refine_result设置路由.就像是
match '/profile/refine_results' => 'profile#refine_results',:as => 'refine_results' 然后你可以使用 .status-bar = link_to "",refine_results_url(profile_id: 1,message_id: 100,new_rating: "awful"),remote: true (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails-3 – Rails中关联的空对象模式
- oracle11g – 使用wm_concat()获取ORA-22922(不存在的LOB值
- poj 1976 A Mini Locomotive 有依赖的背包问题
- 在C中的向量矢量上使用“unique()”
- SQLite 事务处理
- Vue.js基础指令实例讲解(各种数据绑定、表单渲染大总结)
- PHP7.1之上关于json_encode转化小数后失精的问题!
- ruby-on-rails – 为什么rails默认忽略.bundle?
- ruby-on-rails – 递归地将包含非UTF字符的哈希转换为UTF
- ruby-on-rails – Rails上的Ruby / PgSQL错误启动:无法加载