Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 749333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:25:21+00:00 2026-05-14T14:25:21+00:00

How would I correctly call the create action from a link_to? I’m using REST

  • 0

How would I correctly call the create action from a link_to? I’m using REST (map.resources :recipes). 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:25:21+00:00Added an answer on May 14, 2026 at 2:25 pm

    That should work if you substitute recipes_path for recipe_path.

    If you look at the output of rake routes, you should see something like:

    recipes GET /recipes(.:format) {:controller=>"recipes", :action=>"index"}
            POST /recipes(.:format) {:controller=>"recipes", :action=>"create"}
    

    That’s a clue that the URL helper (“recipes_path”), for the create action is made up from the controller name with _path tacked on the end, using :method => :post. The same path using :method => :get (which is the default) maps to the index action.

    Remember this won’t work if Javascript is disabled, because Rails is actually adding an on_click handler that creates a form to do the POST. Same goes for delete links with the :confirm option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like a little confirmation that I'm doing this correctly. Using rails single
I'm unable to transition from index.html to any pages correctly. All transitions would show
I would like to create a temp file, write to the file-handle then call
I am using following C function to create multiple network namespaces from a single
I'm currently working on what I would call integration tests. I want to verify
How would I CORRECTLY round a BigDecimal to the nearest whole value? For instance
I have trouble finding way to correctly refactor this code so that there would
Please show me how i should correctly execute system proccess in java. I would
setup Controller -> Action Index results = Model.all (SQL Call) View Loop through and
I'm using Rails 3 and ruby 1.9 I'm trying to create a customized URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.