Ruby on rails 轨道按钮,遥控功能。没有Ajax可能吗?

Ruby on rails 轨道按钮,遥控功能。没有Ajax可能吗?,ruby-on-rails,Ruby On Rails,我想创建一个非常简单的搜索部分。它有一个文本框,用于查询和搜索数据库。我可以在不使用AJAX或JS的情况下创建远程函数调用吗?我可以把它完全保留为“Rails ee”吗 10%> 远程_函数(:url=>{:action=>:fill_in_lots}, :with=>“搜索词”)%> 这不是问题,您需要使用一种称为正式链接的技术。而不是按钮,你把一个从与提交按钮。下面是我用于此目的的帮助器代码: def formal_link_to(*args, &block) options

我想创建一个非常简单的搜索部分。它有一个文本框,用于查询和搜索数据库。我可以在不使用AJAX或JS的情况下创建远程函数调用吗?我可以把它完全保留为“Rails ee”吗

10%>
远程_函数(:url=>{:action=>:fill_in_lots},
:with=>“搜索词”)%>

这不是问题,您需要使用一种称为正式链接的技术。而不是按钮,你把一个从与提交按钮。下面是我用于此目的的帮助器代码:

def formal_link_to(*args, &block)
    options = html_options = name = nil
    if block_given?
      options = args.first
      html_options = args.second
      name = capture(&block)
    else
      name         = args.first
      options      = args.second || {}
      html_options = args.third
    end

    method = html_options.delete(:method) || "POST"
    method = method.to_s.upcase
    url = url_for(options)

    html = "<form class=\"formal-link\" action=\"#{url}\" method=\"post\">"
    html += "<input type=\"hidden\" value=\"#{form_authenticity_token}\" name=\"authenticity_token\" />" 
    html += "<input type=\"hidden\" value=\"#{method}\" name=\"_method\" />" 
    html += link_to(name, "#", html_options)
    html += "</form>"

    if block_given?
      concat(html)
    else
      return html
    end
  end
def formal_link_to(*args,&block)
选项=html\u选项=name=nil
如果给出了block_?
选项=args.first
html_options=args.second
名称=捕获(&block)
其他的
name=args.first
选项=args.second | |{}
html_options=args.third
结束
method=html_选项。删除(:method)| |“POST”
method=method.to_.upcase
url=url\u用于(选项)
html=“”
html+=“”
html+=“”
html+=链接到(名称,“#”,html#选项)
html+=“”
如果给出了block_?
concat(html)
其他的
返回html
结束
结束
您可以像使用普通链接一样使用此帮助程序,但可以在第二个哈希中传递额外的选项:方法。例如:

<%= formal_link_to "Fill in lots", { :action => "fill_in_lots" }, { :method => :post } -%>
“填充批次”},{:method=>:post}-%>
备注: 1.这当然会使整个页面重新加载,但如果不使用JavaScript,这是不可避免的。 2.我假设action fill_in_lots会受到POST请求的影响。在GET的情况下,您可以使用到帮助器的普通链接

<%= formal_link_to "Fill in lots", { :action => "fill_in_lots" }, { :method => :post } -%>