0

I have a very weird behavior by Rails 3.2.

I use a form_tag in my haml page:

= form_tag messages_path, :method => :get do

this form contains some checkboxes and this code works fine.

But I don't like get.

If I substitute "get" with "post" something really weird happens:

It appears that the control goes to my "create" method, creates a nil object in my db and then goes back to the original page (that's what I told the "create" method to do anyways).

Then, the checkboxes are pretty messed up...

Note: I save the checkbox contents in the session. Dunno, if it really matters.

Seems like "post" takes you to "create" by default ?? Can I change that ? "Get" works fine but messes up my url....

any suggestions ???

4

1 回答 1

2

是的,默认情况下 post 将请求映射到控制器的 create 方法。

如果您想使用发布请求,请在 config/routes.rb 中添加以下代码

resources :messages do
  collection do
    post 'stuff'
  end
end

在您的消息控制器中

def stuff
  #your stuff goes here
end

然后表单生成器将是

form_tag stuff_messages_path, :method => :post
于 2012-10-17T16:49:27.307 回答