Forum: Ruby on Rails Redirecting from a View

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.
80159acdf89580a20e8e835772b5bf82?d=identicon&s=25 Doug Jolley (ddjolley)
on 2009-05-01 07:25
(Received via mailing list)
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-01 09:46
(Received via mailing list)
On May 1, 6:24 am, doug <ddjol...@gmail.com> 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
80159acdf89580a20e8e835772b5bf82?d=identicon&s=25 Doug Jolley (ddjolley)
on 2009-05-01 17:31
(Received via mailing list)
> 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
710eb9516d466362bc80a2f8d3c31cab?d=identicon&s=25 Chris Hanks (preciousbodilyfluids)
on 2009-05-01 17:51
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-cont...
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2009-05-01 18:19
(Received via mailing list)
On Fri, May 1, 2009 at 8:30 AM, djolley <ddjolley@gmail.com> 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 %>
<!-- display things -->

Don't throw the baby out with the bathwater... :-)

>   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 Schroeder ------------------------ hassan.schroeder@gmail.com
80159acdf89580a20e8e835772b5bf82?d=identicon&s=25 Doug Jolley (ddjolley)
on 2009-05-02 17:30
(Received via mailing list)
> 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
80159acdf89580a20e8e835772b5bf82?d=identicon&s=25 Doug Jolley (ddjolley)
on 2009-05-02 18:01
(Received via mailing list)
> 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-cont...
> --
> 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
This topic is locked and can not be replied to.