OK, I'm trying to understand the best methods for CREATE and UPDATE methods for HTML and XML formats. The default code for the controller that generates the rail generator is a bit unclear to me.
For the CREATE method, given good preservation, the generator says " redirect_to (@whatever) " for HTML and " render: xml => @whatever ,: status =>: created ,: location => @whatever " for XML.
Given poor persistence, the generator says " render: action => 'new' for HTML and render: xml => @ whatever.errors ,: status =>: unprocessable_entity " for XML.
However, for the UPDATE method, given a good update, the generator says " redirect_to (@whatever) " for HTML and " head: ok " for XML.
And given the poor update, the generator says " render: action => 'edit' " for HTML and render: xml => @ whatever.errors ,: status =>: unprocessable_entity "for XML.
I understand this, and it makes sense to me, and it works fine - BUT, I have two questions:
First, for a successful CREATE and UPDATE, HTML format, why is " redirect_to (@whatever) " instead of " render: action => 'show' "? I understand the differences between redirecting and rendering, just more curious how you guys tend to do this and why. Redirecting would seem like an extra trip for the browser.
Secondly, why is " head: ok " after successful UPDATE via XML, but " render: xml => @whatever ,: status =>: created ,: location => @whatever " after successfully creating CREATE via XML? It seems inconsistent to me. It seems that a successful UPDATE via XML should be the same as a successful CREATE via XML. It looks like you will need a new / updated object so you can test it. How do you do it and why?