Double render/redirect philosophy

Ok, I think I understand why RoR will flag an attempt double render in
an action.

What I don’t understand is the philosophy of render and redirect_to.

Specifically, why isn’t a return implicit in both those methods?

Or, I guess, more to the point … what are the advantages of writing
code in the action after a render/redirect_to?

There isn’t much point in writing code after a render/redirect in a
controller method, and it’s safe to say it’s a best practice not to. I
think the main reason render/redirect work the way they do is to make
it easier to use those methods in before/after_filters.

For what it’s worth, Merb’s render/redirect implementation is what you
suggest here.

On 9/2/2010 3:04 AM, Ralph S. wrote:

Ok, I think I understand why RoR will flag an attempt double render in
an action.

What I don’t understand is the philosophy of render and redirect_to.

Specifically, why isn’t a return implicit in both those methods?

Or, I guess, more to the point … what are the advantages of writing
code in the action after a render/redirect_to?

I’m not sure how Rails works, but in a C++ HTTP server that we did, we
could do something like write the response to the browser and then do
the remaining house-keeping tasks. For example, it would be perfectly
fine to update the logs, perform some other calculation, etc. that does
not affect the output (since it’s been sent off already) but is
something that the system could use.

In another system, we did something like receive a request by HTTP POST,
check the parameters and acknowledge the receipt of the request to the
client as the response. Thereafter, we needed to process the request
(which took quite a while) and then we would POST the results to a URL
on the client’s side.

I think both these cases would be things that don’t need to be put into
an after_filter and would benefit from writing code in the action after
a render (assuming Rails works/ allows one to work this way).

Cheers,
Mohit.
9/2/2010 | 3:26 AM.

On Feb 8, 2:04 pm, Ralph S. [email protected] wrote:

Ok, I think I understand why RoR will flag an attempt double render in
an action.

What I don’t understand is the philosophy of render and redirect_to.

Specifically, why isn’t a return implicit in both those methods?

Unless I’ve completely missed something, there isn’t a straightforward
way to issue a nonlocal return in Ruby - which you’d need in order to
make calling ‘render’ return from the controller action. One could, of
course, hack up something involving raise/rescue, but that’s going to
be messy.

–Matt J.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs