Redirecting from a View

I’d sure like to be able to insert a redirect_to within a rescue
clause of a view. Anyone have any ideas how I might be able to do
that? Thanks for any input.

      ... doug

On May 1, 6:24 am, doug [email protected] wrote:

I’d sure like to be able to insert a redirect_to within a rescue
clause of a view. Anyone have any ideas how I might be able to do
that? Thanks for any input.

      ... doug

This sounds messy. Views should be dumb data displayers, not making
decisions about whether to redirect or not. What are you trying to
do ?

Fred

This sounds messy. Views should be dumb data displayers, not making
decisions about whether to redirect or not. What are you trying to
do ?

You know what, Fred? You’re absolutely right. I thought about it
over night and that’s the exact conclusion I came to. If one feels a
need to re-direct from a view, that’s a great big flag that he’s
probably doing in the view what should be done in the controller.

A lot of bytes have been spilled over the issue of how much logic
should be put in the view. I am now coming to the conclusion that
it’s a whole lot less than I had previously thought. In fact, I am
fast becoming of the opinion that it’s pretty much down to none. The
reason is that, in general, logic doesn’t stand alone but requires
error checking. It’s the additional complexity of the error checking
that sort of pushes everything into the controller. So, hence forth
my design philosophy is going to be to keep all logic in the
controller. I’ll return a hash to the view containing everything that
I need to plug into the view and that’s it.

Thanks a batch for the input and confirming my thinking.

        ... doug

You don’t want to cram too much into your controllers either. The design
philosophy is “skinny controllers, fat models.”

http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model

On Fri, May 1, 2009 at 8:30 AM, djolley [email protected] wrote:

A lot of bytes have been spilled over the issue of how much logic
should be put in the view. I am now coming to the conclusion that
it’s a whole lot less than I had previously thought. In fact, I am
fast becoming of the opinion that it’s pretty much down to none.

Hold on now – display logic definitely belongs in the view, e.g.
<% if @things.empty? %>
some meaningful alternative message
<% else %>

Don’t throw the baby out with the bathwater… :slight_smile:

I’ll return a hash to the view containing everything that
I need to plug into the view and that’s it.

Great, as long as you’re not generating markup in your controller.


Hassan S. ------------------------ [email protected]

Hold on now – display logic definitely belongs in the view, e.g.

You’re right. I may have gone to far with my statement. For example,
I have encountered some instances where I wanted to loop through data
in order to present a display. It’s far better to loop through the
data and create the display in the view than it is to pass the loop
output to the view. Anyway, the thing is that I think that I have
been putting to much logic in the view. That can easily be seen from
my original question where I wanted to redirect from a view. I’m
going to be more cognizant of this in the future by forcing myself to
justify any inclusions of significant logic in the view. Thanks.

     ... doug

You don’t want to cram too much into your controllers either. The design
philosophy is “skinny controllers, fat models.”

Buckblog: Skinny Controller, Fat Model

Posted viahttp://www.ruby-forum.com/.

Wow! Excellent reference. The role of models has always been elusive
to me. It has always appeared to me that a model was something to be
used only with a database. How did I come to that conclusion? Models
descend from ActiveRecord::Base. A cursory reading of your reference
seems to indicate that models are much more. One thing that seemed to
leap out at me was that a model could be a mechanism for passing data
which was common to all views. Anyway, I have to study this in more
detail and do some playing with it. Thanks for the input.

       ... doug