It seems odd to me that the layout is processesed after the view. When I set a variable inside the view it does not have an impact on the layout file. But when I set it in the controller it does. Is this the way it works or is it possible that I am doing something wrong?
On Thu, 10 Mar 2005 15:50:47 -0500, John Baku <john-CC0oh5EnFfVBDgjK7y7TUQ@public.gmane.org> wrote:> It seems odd to me that the layout is processesed after the view. When I set a > variable inside the view it does not have an impact on the layout file. But > when I set it in the controller it does.That sounds odd, because a variable set in the view should be available in the layout, see the documentation[1] for usage: "Layouts have access to variables specified in the content pages and vice versa. This allows you to have layouts with references that won''t materialize before rendering time: <h1><%= @page_title %></h1> <%= @content_for_layout %> …and content pages that fulfill these references at rendering time: <% @page_title = "Welcome" %> Off-world colonies offers you a chance to start a new life" [1]: http://rails.rubyonrails.com/classes/ActionController/Layout/ClassMethods.html
I tried again and it does not work. They have access to variable specified in each. But which one is set first? It can''t be vice versa. One has to come before the other. On 10-Mar-05, at 4:20 PM, Johan Sörensen wrote:> On Thu, 10 Mar 2005 15:50:47 -0500, John Baku <john-CC0oh5EnFfVBDgjK7y7TUQ@public.gmane.org> wrote: >> It seems odd to me that the layout is processesed after the view. >> When I set a >> variable inside the view it does not have an impact on the layout >> file. But >> when I set it in the controller it does. > > That sounds odd, because a variable set in the view should be > available in the layout, see the documentation[1] for usage: > > "Layouts have access to variables specified in the content pages and > vice versa. This allows you to have layouts with references that won''t > materialize before rendering time: > <h1><%= @page_title %></h1> > <%= @content_for_layout %> > > > …and content pages that fulfill these references at rendering time: > <% @page_title = "Welcome" %> > Off-world colonies offers you a chance to start a new life" > > [1]: > http://rails.rubyonrails.com/classes/ActionController/Layout/ > ClassMethods.html > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Your Friend, Jonathan Kopanas http://www.kopanas.com
On Thu, 10 Mar 2005 18:47:00 -0500, John Baku <john-CC0oh5EnFfVBDgjK7y7TUQ@public.gmane.org> wrote:> I tried again and it does not work. > > They have access to variable specified in each. But which one is set > first? It can''t be vice versa. One has to come before the other.You shouldn''t really be setting variables in your views and expecting them to work in your layouts. The job of a view in an MVC application is to *display* objects prepared by the controllers. If you''re preparing data in the view, it''s generally a sign you''ve coupled the two a little too tightly.> On 10-Mar-05, at 4:20 PM, Johan Sörensen wrote: > > > On Thu, 10 Mar 2005 15:50:47 -0500, John Baku <john-CC0oh5EnFfVBDgjK7y7TUQ@public.gmane.org> wrote: > >> It seems odd to me that the layout is processesed after the view. > >> When I set a > >> variable inside the view it does not have an impact on the layout > >> file. But > >> when I set it in the controller it does. > > > > That sounds odd, because a variable set in the view should be > > available in the layout, see the documentation[1] for usage: > > > > "Layouts have access to variables specified in the content pages and > > vice versa. This allows you to have layouts with references that won''t > > materialize before rendering time: > > <h1><%= @page_title %></h1> > > <%= @content_for_layout %> > > > > > > …and content pages that fulfill these references at rendering time: > > <% @page_title = "Welcome" %> > > Off-world colonies offers you a chance to start a new life" > > > > [1]: > > http://rails.rubyonrails.com/classes/ActionController/Layout/ > > ClassMethods.html > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > Your Friend, > > Jonathan Kopanas > http://www.kopanas.com > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
Good point... thanks :-). Controller it is! On 10-Mar-05, at 6:53 PM, Michael Koziarski wrote:> On Thu, 10 Mar 2005 18:47:00 -0500, John Baku <john-CC0oh5EnFfVBDgjK7y7TUQ@public.gmane.org> wrote: >> I tried again and it does not work. >> >> They have access to variable specified in each. But which one is set >> first? It can''t be vice versa. One has to come before the other. > > You shouldn''t really be setting variables in your views and expecting > them to work in your layouts. The job of a view in an MVC > application is to *display* objects prepared by the controllers. If > you''re preparing data in the view, it''s generally a sign you''ve > coupled the two a little too tightly. > >> On 10-Mar-05, at 4:20 PM, Johan Sörensen wrote: >> >>> On Thu, 10 Mar 2005 15:50:47 -0500, John Baku <john-CC0oh5EnFfVBDgjK7y7TUQ@public.gmane.org> >>> wrote: >>>> It seems odd to me that the layout is processesed after the view. >>>> When I set a >>>> variable inside the view it does not have an impact on the layout >>>> file. But >>>> when I set it in the controller it does. >>> >>> That sounds odd, because a variable set in the view should be >>> available in the layout, see the documentation[1] for usage: >>> >>> "Layouts have access to variables specified in the content pages and >>> vice versa. This allows you to have layouts with references that >>> won''t >>> materialize before rendering time: >>> <h1><%= @page_title %></h1> >>> <%= @content_for_layout %> >>> >>> >>> …and content pages that fulfill these references at rendering time: >>> <% @page_title = "Welcome" %> >>> Off-world colonies offers you a chance to start a new life" >>> >>> [1]: >>> http://rails.rubyonrails.com/classes/ActionController/Layout/ >>> ClassMethods.html >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >> >> Your Friend, >> >> Jonathan Kopanas >> http://www.kopanas.com >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > Cheers > > Koz > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Your Friend, Jonathan Kopanas http://www.kopanas.com
On Fri, 11 Mar 2005 12:53:19 +1300, Michael Koziarski <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You shouldn''t really be setting variables in your views and expecting > them to work in your layouts.Why not? Works perfectly fine for me. I use this functionality for setting the title of the page in the view, and putting that into the ''title'' tag in the layout.> The job of a view in an MVC > application is to *display* objects prepared by the controllers. If > you''re preparing data in the view, it''s generally a sign you''ve > coupled the two a little too tightly.You make a good point, but it''s not like I''m doing sql queries in the views, it''s just assigning a string. I thought about putting that into the controller, but the controller was so elegant, I didn''t want to clutter it up with the text that''s to appear in the title of the website. The specific text used for the title seemed more like a detail of the view than some important piece of data that the controller should be setting. -- One Guy With A Camera http://rbpark.ath.cx
On Thu, 10 Mar 2005 21:24:11 -0700, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Fri, 11 Mar 2005 12:53:19 +1300, Michael Koziarski > <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > You shouldn''t really be setting variables in your views and expecting > > them to work in your layouts. > > Why not? Works perfectly fine for me. I use this functionality for > setting the title of the page in the view, and putting that into the > ''title'' tag in the layout. > > > The job of a view in an MVC > > application is to *display* objects prepared by the controllers. If > > you''re preparing data in the view, it''s generally a sign you''ve > > coupled the two a little too tightly. > > You make a good point, but it''s not like I''m doing sql queries in the > views, it''s just assigning a string. I thought about putting that into > the controller, but the controller was so elegant, I didn''t want to > clutter it up with the text that''s to appear in the title of the > website. The specific text used for the title seemed more like a > detail of the view than some important piece of data that the > controller should be setting.I''m doing the same thing to set the title and create the bookmark links. Works fine with a layout. I''ll probably end up putting this in the controller just because it clutters my view up with code. -- rick http://techno-weenie.net
Maybe for me it is different because I set the default value in the application and it uses that before I reset value in view. On 11-Mar-05, at 12:52 PM, Rick Olson wrote:> On Thu, 10 Mar 2005 21:24:11 -0700, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On Fri, 11 Mar 2005 12:53:19 +1300, Michael Koziarski >> <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> You shouldn''t really be setting variables in your views and expecting >>> them to work in your layouts. >> >> Why not? Works perfectly fine for me. I use this functionality for >> setting the title of the page in the view, and putting that into the >> ''title'' tag in the layout. >> >>> The job of a view in an MVC >>> application is to *display* objects prepared by the controllers. If >>> you''re preparing data in the view, it''s generally a sign you''ve >>> coupled the two a little too tightly. >> >> You make a good point, but it''s not like I''m doing sql queries in the >> views, it''s just assigning a string. I thought about putting that into >> the controller, but the controller was so elegant, I didn''t want to >> clutter it up with the text that''s to appear in the title of the >> website. The specific text used for the title seemed more like a >> detail of the view than some important piece of data that the >> controller should be setting. > > I''m doing the same thing to set the title and create the bookmark > links. Works fine with a layout. > > I''ll probably end up putting this in the controller just because it > clutters my view up with code. > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Your Friend, Jonathan Kopanas http://www.kopanas.com