I’m using Devise with Rails 3.1 and I have generated all the views for Devise.
I want any Devise view to be wrapped in a div:
<div class="devise-container">
<!-- Devise view -->
</div>
At the moment I have manually added this to every Devise view, but this is not very DRY. Is there a better way?
Assuming you are using the Devise controllers and have not overridden them, you can create a layout called “devise.html.haml” or “devise.html.erb” (or whatever templating language you use) in the usual app/views/layouts/ directory and add the custom code you need.
This layout should then automatically get loaded and override you application controller because the layout name matches the controller name.
However, that said, a better solution may be to add a class to the tag of your application layout with the current controller name (controller.name) and use CSS to manage the problem by adding a custom style only to “body.devise” pages. This solution is more flexible and adds less clutter to your application code, seeing as it is a presentation problem.