In my layout, I have something like (shortened for clarity): <html> <head> <%= stylesheet_link_tag "index", :media => "all" %> </head> <body> <div id="site-container"> ... <cut for space> <%= @content_for_layout %> ... <cut for space> </div> </body> A view action has another stylesheet defined in the opening line such as: <%= stylesheet_link_tag "view_posts", :media => "all" %> <div id="left-column"> blah, blah, blah </div> The layout has the appropriate stylesheet for common layout features. The actions each have their own stylesheets so that the main stylesheet isn''t 2000 lines long. :) Now, the problem is that when I include a stylesheet link tag in the top of my action view, essentially that css definition is in a div tag on the overall page. The validator gives me a warning about this, but it does work. I''m sure there must be a more appropriate way to handle this, but I''m not sure what it might be. Any suggestions? Thanks, David
Hey David, What I am about to suggest is not very elegant. I might go as far as "hacky". (1) In your controller. def my_action @custom_styles = [''my_action'',''some_other_style''] # Do stuff end (2) In you layout, just before the </head> tag: <% if @custom_styles %> <% for s in @custom_styles %> <%= stylesheet_link_tag s, :media => "screen" %> <% end %> <% end %> HTH ~Rohith On 6/22/06, David M <lists@codecharter.com> wrote:> > In my layout, I have something like (shortened for clarity): > > <html> > <head> > <%= stylesheet_link_tag "index", :media => "all" %> > </head> > <body> > <div id="site-container"> > ... <cut for space> > <%= @content_for_layout %> > ... <cut for space> > </div> > </body> > > A view action has another stylesheet defined in the opening line such as: > <%= stylesheet_link_tag "view_posts", :media => "all" %> > <div id="left-column"> > blah, blah, blah > </div> > > The layout has the appropriate stylesheet for common layout features. The > actions each have their own stylesheets so that the main stylesheet isn''t > 2000 lines long. :) Now, the problem is that when I include a stylesheet > link tag in the top of my action view, essentially that css definition is > in a div tag on the overall page. The validator gives me a warning about > this, but it does work. I''m sure there must be a more appropriate way to > handle this, but I''m not sure what it might be. Any suggestions? > > Thanks, > David > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060622/37533e30/attachment.html
> In my layout, I have something like (shortened for clarity): > > <html> > <head> > <%= stylesheet_link_tag "index", :media => "all" %> > </head> > <body> > <div id="site-container"> > ... <cut for space> > <%= @content_for_layout %> > ... <cut for space> > </div> > </body> > > A view action has another stylesheet defined in the opening line such as: > <%= stylesheet_link_tag "view_posts", :media => "all" %> > <div id="left-column"> > blah, blah, blah > </div> > > The layout has the appropriate stylesheet for common layout features. The > actions each have their own stylesheets so that the main stylesheet isn''t > 2000 lines long. :) Now, the problem is that when I include a stylesheet > link tag in the top of my action view, essentially that css definition is > in a div tag on the overall page. The validator gives me a warning about > this, but it does work. I''m sure there must be a more appropriate way to > handle this, but I''m not sure what it might be. Any suggestions?We do this in our layout: <%= yield "page_styles" %> Then in our views do this: <% content_for("page_styles") do %> <%= stylesheet_link_tag "#{params[:controller]}/main" %> <%= stylesheet_link_tag "#{params[:controller]}/#{params[:action]}" %> <% end %> or whatever links to stylesheets you want... Works for us. -philip
I like Philip''s method better. It does not require creating a meaningless instance variable(and code) and it feels like "the right way" ;-) ~R On 6/22/06, Philip Hallstrom <rails@philip.pjkh.com> wrote:> > > In my layout, I have something like (shortened for clarity): > > > > <html> > > <head> > > <%= stylesheet_link_tag "index", :media => "all" %> > > </head> > > <body> > > <div id="site-container"> > > ... <cut for space> > > <%= @content_for_layout %> > > ... <cut for space> > > </div> > > </body> > > > > A view action has another stylesheet defined in the opening line such > as: > > <%= stylesheet_link_tag "view_posts", :media => "all" %> > > <div id="left-column"> > > blah, blah, blah > > </div> > > > > The layout has the appropriate stylesheet for common layout > features. The > > actions each have their own stylesheets so that the main stylesheet > isn''t > > 2000 lines long. :) Now, the problem is that when I include a > stylesheet > > link tag in the top of my action view, essentially that css definition > is > > in a div tag on the overall page. The validator gives me a warning > about > > this, but it does work. I''m sure there must be a more appropriate way > to > > handle this, but I''m not sure what it might be. Any suggestions? > > We do this in our layout: > > <%= yield "page_styles" %> > > Then in our views do this: > > <% content_for("page_styles") do %> > <%= stylesheet_link_tag "#{params[:controller]}/main" %> > <%= stylesheet_link_tag "#{params[:controller]}/#{params[:action]}" %> > <% end %> > > or whatever links to stylesheets you want... > > Works for us. > > -philip > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060623/1dcbb13d/attachment.html
It also works very well for putting javascript that absolutely has to go at the very end of the output because IE is stupid :-) On Thu, 22 Jun 2006, Rohith Ravi wrote:> I like Philip''s method better. It does not require creating a meaningless > instance variable(and code) and it feels like "the right way" ;-) > > ~R > > On 6/22/06, Philip Hallstrom <rails@philip.pjkh.com> wrote: >> >> > In my layout, I have something like (shortened for clarity): >> > >> > <html> >> > <head> >> > <%= stylesheet_link_tag "index", :media => "all" %> >> > </head> >> > <body> >> > <div id="site-container"> >> > ... <cut for space> >> > <%= @content_for_layout %> >> > ... <cut for space> >> > </div> >> > </body> >> > >> > A view action has another stylesheet defined in the opening line such >> as: >> > <%= stylesheet_link_tag "view_posts", :media => "all" %> >> > <div id="left-column"> >> > blah, blah, blah >> > </div> >> > >> > The layout has the appropriate stylesheet for common layout >> features. The >> > actions each have their own stylesheets so that the main stylesheet >> isn''t >> > 2000 lines long. :) Now, the problem is that when I include a >> stylesheet >> > link tag in the top of my action view, essentially that css definition >> is >> > in a div tag on the overall page. The validator gives me a warning >> about >> > this, but it does work. I''m sure there must be a more appropriate way >> to >> > handle this, but I''m not sure what it might be. Any suggestions? >> >> We do this in our layout: >> >> <%= yield "page_styles" %> >> >> Then in our views do this: >> >> <% content_for("page_styles") do %> >> <%= stylesheet_link_tag "#{params[:controller]}/main" %> >> <%= stylesheet_link_tag "#{params[:controller]}/#{params[:action]}" %> >> <% end %> >> >> or whatever links to stylesheets you want... >> >> Works for us. >> >> -philip >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >