Forum: Ruby on Rails alternative form processing pattern

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-03-25 21:14
(Received via mailing list)
Scaffolds generate new/create-like pairs to process forms. +new+
renders the form, and +create+ process it. If successful +create+
redirects to some view with no side-effects like +show+.

Now, if +create+ fails, we usually render :action => 'new' to present
the form again together with error messages. Albeit being the reponse
to a POST request the browser then changes the URL in the navigation
bar from ".../new" to ".../create". Both Safari and Firefox do that.

I don't like that mixture of actions in the navigation bar. I could
prevent +create+ from responding to GET requests, in case browser
completion hits that cached URL, but am thinking everything would be
cleaner if +new+ could handle both rendering and processing.

If I delete +create+ and program +new+ so that it renders the form in
response to GET, and process the form in response to POST, everything
looks easier AFAICT and the URL stays the same if validation fails.
Do you foresee any drawback in that pattern? Does anybody use it?

-- fxn
Dcbf676f860477e44b275cae5d6318a4?d=identicon&s=25 Piotr Usewicz (lopmx)
on 2006-03-26 20:02
(Received via mailing list)
Xavier Noria napisaƅ?(a):
> prevent +create+ from responding to GET requests, in case browser
> completion hits that cached URL, but am thinking everything would be
> cleaner if +new+ could handle both rendering and processing.
>
> If I delete +create+ and program +new+ so that it renders the form in
> response to GET, and process the form in response to POST, everything
> looks easier AFAICT and the URL stays the same if validation fails. Do
> you foresee any drawback in that pattern? Does anybody use it?
>
> -- fxn

No there are no drawbacks. In fact, CD Baby.com uses the same approach.
This topic is locked and can not be replied to.