Keith Lancaster
2005-Sep-26 14:10 UTC
Nuby question concerning layouts / components / partials
I''m prototyping an app that has a basic 3 column layout, with the left column being for logging in. Once the user is logged in, the right column should disappear and the left should change to information about who is logged in, etc. Being new to rails, I am struggling a bit with the best way to approach this. I started down the path of componentizing the login box, but then became confused as to where to locate the user model that is associated with the login (I have implemented the login using the basic login generator from the wiki). What I have right this instant is an application layout that handles switching content based on whether the user is logged in. Is this the best way to go, or should I pursue the component route? Partials? Changing layouts? TIA, Keith
Richard Sandilands
2005-Sep-26 21:08 UTC
Re: Nuby question concerning layouts / components / partials
> Is this the best way to go, or should I pursue the component route? > Partials? Changing layouts?I''m new to this as well but I suppose I would have conditionally inserted a partial depending on whether the user is logged in. Richard
Keith Lancaster
2005-Sep-26 21:43 UTC
Re: Nuby question concerning layouts / components / partials
That''s the way I was leaning. I''m trying to use style sheets for all of the layout, so I guess I would have each partial have a different (div) ID (to allow for different positioning)? I''m getting close to the results I want, but am having a bit of a time keeping track of where information is best kept: style sheets, partials, layouts, views. Guess I''ll figure it out over time. :-) Anyway, thanks for the input. Keith On 9/26/05, Richard Sandilands <infoarts-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Is this the best way to go, or should I pursue the component route? > > Partials? Changing layouts? > > I''m new to this as well but I suppose I would have conditionally > inserted a partial depending on whether the user is logged in. > > Richard >
Rick Olson
2005-Sep-26 21:44 UTC
Re: Nuby question concerning layouts / components / partials
On 9/26/05, Richard Sandilands <infoarts-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Is this the best way to go, or should I pursue the component route? > > Partials? Changing layouts? > > I''m new to this as well but I suppose I would have conditionally > inserted a partial depending on whether the user is logged in.There''s many ways you could do this: <%= render :partial => (logged_in? ? ''login_column'' : ''other_column'') %> Or <%= render(:partial => ''login_column'') if logged_in? -%> <%= render(:partial => ''other_column'') unless logged_in? -%> -- rick http://techno-weenie.net
Ezra Zygmuntowicz
2005-Sep-26 22:09 UTC
Re: Nuby question concerning layouts / components / partials
Keith- The way I am doing stuff like you are trying to do is to conditionally use the render_component call in the views but I don''t bother with the actual components directory. You can just use the render_component call with _any_ controller and action. The only thing to remember is to use the render_without_layout call in the action. If you have any other views that use the same action with a layout you can do something like this: # renders a minimal print layout when called by an url that includes : /controller/vo/23?print=1 def vo if params[:print] render :layout => "print_version" && return else @params render :layout => "voice_tmpl" end end # or use the same thing to render without layout: # call with /controller/vo2/24?inc=true def vo2 if params[:inc] render :layout => false && return else @params render :layout => "voice_tmpl" end end This might not be exactly what you want but take a look here : <http://yakimaherald.com> I use this type of stuff to render the side bars and other little components. You can call them in your views like so: <%= render_component :controller =>"page", :action => "vo", :params => { :inc => "true" } %> Hope that helps some- -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org On Sep 26, 2005, at 2:43 PM, Keith Lancaster wrote:> That''s the way I was leaning. I''m trying to use style sheets for all > of the layout, so I guess I would have each partial have a different > (div) ID (to allow for different positioning)? I''m getting close to > the results I want, but am having a bit of a time keeping track of > where information is best kept: style sheets, partials, layouts, > views. Guess I''ll figure it out over time. :-) Anyway, thanks for the > input. > > Keith > > On 9/26/05, Richard Sandilands <infoarts-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>> Is this the best way to go, or should I pursue the component route? >>> Partials? Changing layouts? >>> >> >> I''m new to this as well but I suppose I would have conditionally >> inserted a partial depending on whether the user is logged in. >> >> Richard >> >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >