BodyId
Create a custom body_id
from your controller and action names.
Pages#index #=> #page-index
Cars#new #=> #car-new
Installation
Add this line to your application's Gemfile:
gem 'body_id'
And then execute:
$ bundle
Or install it yourself as:
$ gem install body_id
Usage
In your application.html.erb
, or other layout files set, body_id
as the body tag's ID
ERB
...
</head>
<body id= <%= body_id %>>
<%= yield %>
</body>
</html>
HAML
...
%body{ id: "#{ body_id }" }
...
Custom body_id
In case you want a custom ID for your body tag, simply create an instance variable with what you want the view's body_id to be.
class PagesContrller < ApplicationController
def index
@body_id = 'home'
end
def new
@body_id = 'awesome-custom-id'
end
end
Contributing
- Fork it ( http://github.com/the4dpatrick/body-id-gem )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request