Ruby on Rails: Can I do a "link_to" to call a create action?

Posted by sjsc on Stack Overflow See other posts from Stack Overflow or by sjsc
Published on 2010-04-23T21:48:43Z Indexed on 2010/04/23 21:53 UTC
Read the original article Hit count: 269

Filed under:
|

How would I correctly call the create action from a link_to? Here's the create action:

def create
  recipe = Recipe.create(:name => "French fries")
  redirect_to recipe
end

For example, I thought something like this might work:

<%= link_to "Create a default recipe", recipe_path, :method => :post %>

I'm not sure if that's a recommended (or even correct) way to do it. Any idea?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails