Stylesheet depends on hostname

Sorry my English

I'm working on multi face site, that runs on Sintra. I need to change CSS stylesheet in depend of given URL. Like:

get '/*' do
    when ''
        @style = 'style1'
    when ''
        @style = 'style2'
    erb :index

Then in index.erb view:

<link rel="stylesheet" src="../<%= @style %>.css">

But if place code like this in action file, all pages content is "style1" or "style2". To prevent this I need to place case code in every get-do action. I think this is not the Ruby way. Is there exists any possible way to place that "stylesheet rewrite" in single action or another way to implement css rewriting in this case? Thank you in advance.


This is a very good reason for using a helper method. First add the helper:

helpers do
  def include_css(host)
    case host
    when ''
    when ''

Then in your index.erb:

<link rel="stylesheet" src="../<%= include_css( %>.css">

Disclaimer: I don't use ERB so it might not work out-of-the-box. Also, I don't know whether index.erb is a template common to all your pages, so maybe you'll have to put that line in each .erb file you serve.

better call stylesheet by layouts it will b the easy way

Need Your Help

Modify XSLT using C# Code

c# xml xslt visual-studio-2012

I am Working on Visual-studio 2012 in C#.

UIwebview delays loading

iphone uiwebview

I have Login screen and second view which will be shown after login. On second view I have UIWebview which loads the url.