Search code examples
ruby-on-railsrubyroutesscaffoldingruby-on-rails-4

Wrong action being generated for form_for on edit


The action for my edit form is being generated wrong. The way I built the model was a little different than usual, I first generated the model using:

rails g model category name:string description:text

I then ran rake db:migrate I then generated the scaffold using:

rails g scaffold_controller Category.

The problem is that in the edit form that was generated the form that is being submitted is to the action category/1 instead of categories/1.

I'm using rails 4. I am not exactly sure how the form action is decided but it is being set up wrong. On the other hand the new category form is working fine, help anyone?

It seems that the form_for is generating the wrong action even though it is supposed to render category_path(@category) but when i print that path out it is correct. Is there anywhere that the form_for helper method is explained well, I've been looking and couldn't find it.


Solution

  • Solution was to remove all changes and generate the scaffold correctly using:

    rails g scaffold Category name:string description:text