繁体   English   中英

使用带有get方法的form_for标记

[英]Using form_for tag with get method

我正在尝试使用get方法提交表单。 早些时候我正在尝试使用form_tag进行类似的操作并且它正在运行但是现在当我更改为form_for标签时,这似乎不起作用。

<%- filter_path = params[:action] == "index" ? posts_path : sneak_peek_posts_path %>
<%= form_for(@post_filter, :url=> filter_path, :method => :get) do |f| %>

我得到一个无路由错误。

如果需要,可以使用:html传递原始HTML属性。 对于Rails 3:

<%= form_for(@post_filter, :url=> filter_path, :html => { :method => 'GET' }) do |f| %>

更新并在Rails 4中,根据@andre.orvalho的建议,可以直接提供method参数:

<%= form_for(@post_filter, url: filter_path, method: :get ) do |f| %>

你试过了吗

<%= form_for(@post_filter, :url=> filter_path, :html => {:method => :get}) do |f| %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM