On Mon, Dec 19, 2011 at 11:56 PM, Steve Klabnik <[email protected]> wrote:
> throw/catch for flow control is bad.
Indeed it is. It's the one thing in Sinatra I always disliked.
If I had to choose, I would go down the path of render/redirect
returning a response, so you would do something like `return render
:new` or `return redirect_to @object`.
This has the added bonus that it's compatible with 99.9% of the uses
of render and redirect (being the last line of an action/conditional)
thanks to the implicit returns.
def create
@obj = Obj.new(…)
if @obj.save
redirect_to @obj, notice: …
else
render :new
end
end
That still works as expected.
But if you did:
def create
render :foo
render :bar
end
You get the response generated by "render :bar" and the other one is
ignored. Because it's just an object returned, instead of some black
magic depending on class state.
That said, this would require quite the refactoring in ActionPack.
But it would be much cleaner, IMHO.
Cheers,
-foca
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" 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-core?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" 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-core?hl=en.