Does anyone know why there is no respond_to
block for generated edit
actions? Every other action in typical scaffold controllers has a respond_to
block in order to output html
and xml
formats. Why is the edit
action an exception?
I'm using the latest version of Ruby on Rails (2.1.1).
Rails handles the 99% case: It's fairly unlikely you'd ever need to do any XML or JSON translations in your Edit action, because non-visually, the Edit action is pretty much just like the Show action. Nonvisual clients that want to update a model in your application can call the controller this way
GET /my_models/[:id].xml (Show)
Then, the client app can make any transformations or edits and post (or put) the results to
PUT /my_models/[:id].xml (Update)
When you call this, you usually are doing it to get an editable form of the Show action:
GET /my_models/[:id]/edit
And it is intended for human use. 99% of the time, that is. Since it's unusual to transform the data in the Edit action, Rails assumes you aren't going to, and DRYs up your code by leaving respond_to out of the scaffold.
Somewhat related. Some may wonder why the rails scaffolding for the new action still has a respond_to block; whereas the edit action does not. This is because a request to something like:
GET /my_models/new.xml
...gives back an XML template that can be used to create a new model.
Because the edit action will only be called from HTML There is no need for the edit form to be returned in an XML context. Using REST, you simply make a put call directly to update with the relevant information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With