chris wrote:
> Hey i took your advice and took a closer look at the code scaffold
> generates for my NEW & EDIT views and it seems that form_for takes the
> same argument for edit and new which is the object itself, in this
> case @category.
> 
> I used the form_for and it worked.  can you explain again why it
> works?  that would be really helpful.
> 
> thanks,

Perhaps this will illustrate.

 >> @old_user = User.find :first
=> #<User id: 1, ...>
 >> @old_user.new_record?
=> nil
 >> @new_user = User.new
=> #<User id: nil, ...>
 >> @new_user.new_record?
=> true

form_for() takes the same parameters, but it isn't passed the same 
object for a new record as opposed to an edit of a previously existing 
record, and therefore it doesn't generate the same html.  I haven't 
looked two closely, but the big difference I noticed was that form_for() 
generates the input element with the name "_method" and value "put" when 
new_record? is nil.  The target for the form will be the same for both, 
and the only difference between them as requests go will be that the 
update request will use the PUT method whereas the create request will 
use the POST method.  If you look in your controller, you'll see that 
prior to the create method is this:

# POST /enquiries

and prior to the update method is this:

# PUT /enquiries/1

The target for the form should be "/enquiries" and in rails this is 
given by form_for :enquiry.

When rails inspects the request to determine the route, it will use the 
id from the form and the method to come to the conclusion that the 
target of the update request is PUT /enqueries/:id and the target for 
the create request is POST /enquiries.

Hope that makes sense.

Cheers,
Darrik


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to