From a web application point of view, you're usually done after you
deliver some content to the client, which in Rails means a render or
redirect call usually.
For 99.99% of the cases, there'll be a return following a render or
redirect inside some "if".
Some might prefer something like
(render login_url; return) unless authenticated?
Others will prefer something more verbose like
unless authenticated?
render login_url
return
end
Others will rely on some undocumented feature of render that might
change any time:
render login_url and return unless authenticated?
render (or redirect_to) is not guaranteed to return a truthy value,
specially because it really doesn't make any sense for the returning
result to have any meaning.
So, I'm suggesting that Rails could support some automatic "return"
after each call to render or redirect_to, by calling the method inside a
catch-throw block.
For example:
class Dispatcher
def dispatch(controller, action)
catch :redirected_or_rendered do
controller.send action
end
end
end
class AbstractController
def render(*args) # or redirect_to
do_render(*args)
throw :redirected_or_rendered
end
end
Maybe new method names like render_and_return and redirect_and_return
could be added for backward compatibility, although I would really
prefer to use render and redirect_to with this behavior built-in.
Maybe we could add some option like
"Rails.application.config.automatic_return_from_render_or_redirect = true".
Is there any interest on adding such behavior to Rails?
Cheers,
Rodrigo.
--
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.