I could not find any docs or examples on how to structure my app to allow different views in the same controller to use completely different layouts and stylesheets.
Our app was scaffolded and we then used nifty-generators to generate views, then added devise for authentication. We have views and controllers for two models: widgets and companies.
I currently have a single layout: layouts/application.html.haml, I don’t see that referenced anywhere so I assume (a rails newbie) that it’s always used by naming convention.
I now need to add a couple of views (for mobile browsers) which have a different stylesheet and layout (for example, no login/logout links in the top right), within the same controllers.
How can that be done?
By default,
layouts/application.html.haml(.erbif you are not using haml).In fact, layout file could be set per controller or per action, instead of per view, per view folder.
There are few cases:
To change the default layout file for all controller (ie. use
another.html.hamlinstead ofapplication.html.haml)To change all actions in a certain controller to use another layout file
To change an action to use other layout file