Usually the recommended solution is content_for
in the parent layout file. But this results in having to specify it in every view since the default becomes not displaying it if the content is not present in the child view partial.
For example, if I have a sidebar that I want to hide in authentication pages, but have it everywhere else, I now have to specify content of the sidebar in every view file except the authentication pages. Not DRY.
This is much more cumbersome and not dry than before, where I could render a sidebar partial in the layouts and be done with it (but not have the benefit of choosing where it does or doesn't render).
It would be nice if you could somehow specify in the layouts template that calls the sidebar partial to not tender if it's a session controller or devise controller.
Is there any way to do this? I've tried using
unless devise_controller?
render "layouts/sidebar"
But this doesn't seem to work as intended.
Taking an example with Devise, I have an application.html.slim file like so
.row
main
.col-sm-9
= yield
- unless devise_controller?
.col-sm-3
== render 'layouts/sidebar'
Ignore the columns for a moment. The main point is that the =yield
renders normal templates as well as the devise templates. So I can't selectively disable the sidebar in one DRY stroke. I would have to put the sidebar render call in every view file, but not include it in my devise views. That's no better or DRYer than using content_for in every non-devise view file.
And getting back to the columns, I would like to have the yielded devise views full width of 12 columns, not 9 columns. But that's just bonus, not the main question.