简体   繁体   中英

Using form_for tag with get method

I am trying to Submit a form using get method. Earlier I was trying a similar thing with form_tag and it was working but now when I changed to a form_for tag, this doesn't seem to work.

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

I get a no routes error.

You can pass the raw HTML attributes using :html if you need to. For Rails 3:

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

Update and in Rails 4, per @andre.orvalho's suggestion below, the method parameter can be supplied directly:

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

你试过了吗

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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