Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 使用link_to remote:true将参数传递给rails_Ajax_Ruby On Rails 3_Jquery_Link To Remote - Fatal编程技术网

Ajax 使用link_to remote:true将参数传递给rails

Ajax 使用link_to remote:true将参数传递给rails,ajax,ruby-on-rails-3,jquery,link-to-remote,Ajax,Ruby On Rails 3,Jquery,Link To Remote,因此,我有一个包含多条消息的页面,每个页面都有一个链接,可以更改(细化)该消息的评级。当用户单击此链接时,我需要一个AJAX调用来更新数据库中该消息的相应列值。单击此链接时,任何事情都不会发生。不应刷新或重新加载页面 我一直在尝试使用link_to remote来实现这一点:是的,但我似乎无法让它工作。在线文档在这个问题上相当不清楚,随着Rails2和Rails3之间的更改,不再支持:with之类的内容 到目前为止,我已经复制了我所拥有的,但我知道它离解决方案还很远。 就我需要传递到数据库的参数

因此,我有一个包含多条消息的页面,每个页面都有一个链接,可以更改(细化)该消息的评级。当用户单击此链接时,我需要一个AJAX调用来更新数据库中该消息的相应列值。单击此链接时,任何事情都不会发生。不应刷新或重新加载页面

我一直在尝试使用link_to remote来实现这一点:是的,但我似乎无法让它工作。在线文档在这个问题上相当不清楚,随着Rails2和Rails3之间的更改,不再支持:with之类的内容

到目前为止,我已经复制了我所拥有的,但我知道它离解决方案还很远。 就我需要传递到数据库的参数而言,我需要配置文件id、消息id和新的分级

提前谢谢

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
结果_.rb

class ResultRefinement < ActiveRecord::Base
  attr_accessible :profile_id, :message_id, :new_rating, :deleted

  belongs_to :profile
end
classresultrefinement
您需要先为
ProfileController#优化结果
设置一条路由。差不多

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

令人惊叹的。我让它开始传递参数并将它们保存到数据库中。我现在唯一的问题是阻止页面重定向或更改。似乎另一个js文件正在覆盖ajax。这就是为什么我一直关注链接,而不是让ajax接管。