【问题标题】:Ruby on rails 3: link_to :remote => true treats "remote" as a URL parameterRuby on rails 3:link_to :remote => true 将“remote”视为 URL 参数
【发布时间】:2011-07-17 09:01:07
【问题描述】:

我想知道用于发出 ajax 请求的 link_to 语法应该是什么(或其他关于此处可能出现问题的想法)。目前我有

<%= form_tag "save_sets", :remote => true, :name => "set_form" do %>

在一个文件中,它工作得很好。但是,在同一个文件中,所有的

<%= link_to assignment.name, :action => :view_student_problem_set, :remote => true %>
<%= link_to assignment.name, :remote => true, :action => :view_student_problem_set %>
<%= link_to assignment.name, {:action => :view_student_problem_set, :remote => true} %>
<%= link_to assignment.name, {:remote => true, :action => :view_student_problem_set} %>
<%= link_to assignment.name, {:remote => true}, {:action => :view_student_problem_set} 
<%= link_to assignment.name, {:remote => true}, :action => :view_student_problem_set %>

只需使用“?remote=true”而不是 data-remote="true" 生成链接,并且

<%= link_to assignment.name, :remote => true, {:action => :view_student_problem_set} %>

显然是语法错误。

我尝试过的大多数组合都来自教程、论坛帖子和文档。我不认为符号集合必须按特定顺序排列,但我只是做得很彻底。无论如何,我的谷歌搜索技巧已经达到了他们的水平。

form_tag 和 link_to 标签之间的相关 jquery 代码、控制器代码和诸如此类的东西都是相同的。

谢谢大家。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3


    【解决方案1】:
    <%= link_to assignment.name, {:action => :view_student_problem_set}, :remote => true %>
    

    【讨论】:

    • 哇。谢谢,这行得通。作为一个后续问题,'关于去哪里找到这样的东西有什么建议吗?据我所知,这个页面 (api.rubyonrails.org/classes/ActionView/Helpers/…) 只是说明这是可能的,但没有说明如何实际做到这一点......
    猜你喜欢
    • 2013-03-06
    • 1970-01-01
    • 2016-04-28
    • 2017-06-11
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多