How can I change a body tag ID based on the page title in rails? -


using ruby on rails (5) want use if statement change id of body tag based on view rendering. want use background image on home page only, , not on other. want fill screen, if put on page it's self comes border. want attache body tag in application.html.erb view id tell css load background image. can't :title tell erb there , make statement true.

i using provide on view page so:

<% provide(:title, "home") %> 

then in application.html.erb page trying use if statement put in body tag or without css id background image based on provided :title, so:

<!doctype html> <html>   <head>     <title><%= yield(:title) %></title>     ...   </head>      <% if :title == "home" %>     <body id="home-background">     <% else %>     <body>     <% end %> 

but doesn't seem work. title 'yield' , display in address bar, not in if statement. have tried put yield(:title) in variable , rails didn't that. first solo rails project, , know should possible, can't find how correctly, appreciated.

i wont recommend body tag...but can use wrapper after body background image...it can this:-

the thing need create instance variable(@title) use below

###application.html.erb  <body>    <div class="<%= @title=="user" ? 'user_wrapper' : 'default_wrapper' %>">    </div>  </body>      ##css    .user_wrapper{      background: url(user_background.jpg) no-repeat center center fixed;    }     .default_wrapper{      background: url(default_background.jpg) no-repeat center center fixed;    } 

hope helps.. :)


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -