2012-03-16 15 views
8

getメソッドを使用してフォームを送信しようとしています。以前私はform_tagで同様のことを試していましたが、動作していましたが、今はform_forタグに変更したとき、これはうまくいかないようです。getメソッドでform_forタグを使用する

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

エラーが発生しました。

答えて

18

必要に応じて、生の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| %> 
+0

ありがとうございました。 – nightf0x

+1

あなたはあなたの答えをレール4に更新するべきです:<%= form_for(@post_filter、url:filter_path、method::get)do | f | %> –

+0

url引数をurlパスに追加する方法??? –

2

はあなたが

<%= form_for(@post_filter, :url=> filter_path, :html => {:method => :get}) do |f| %> 
を試してみました
関連する問題