Rails - Do I need to define 'new' action in controller -


in routes.rb have line resources :items. have new.html.erb file using form_for @item ... build form. in items controller define new action:

def new   @item = item.new end 

i wondering point of new action definition. when form submitted have create action handles it. using form_for? happens if leave out? there rails magic going on assume want?

the new creates new object form_for. form_for know submit create (instead of update) because object not persisted. , 'form_for' needs object anyway (as model-backed forms).

new gives opportunity set initial values attributes, if desire.

so, in all, helpful.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -