How can I set ID for body tag in Rails?
<body id="login">
You need to enclose (wrap) your PHP output in a div . And then give id to that div. Also, no need for brackets ( and ) for echo as it is a language construct, not a function.
In HTML5, the id attribute can be used on any HTML element (it will validate on any HTML element.
I don't find any of the solutions particularly elegant or flexible. Add a body_class
method to application_helper.rb:
def body_class
[controller_name, action_name].join('-')
end
..in layout:
<body class="<%= body_class %>">
#e.g output: <body class="articles-show">
You can then refine the above helper to dynamically inject other identifiers such as modules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With