rails 3, how add a view that does not use same layout as rest of app? -


i not find docs or examples on how structure app allow different views in same controller use different layouts , stylesheets.

our app scaffolded , used nifty-generators generate views, added devise authentication. have views , controllers 2 models: widgets , companies.

i have single layout: layouts/application.html.haml, don't see referenced anywhere assume (a rails newbie) it's used naming convention.

i need add couple of views (for mobile browsers) have different stylesheet , layout (for example, no login/logout links in top right), within same controllers.

how can done?

by default, layouts/application.html.haml (.erb if not using haml).

in fact, layout file set per controller or per action, instead of per view, per view folder.

there few cases:

to change default layout file controller (ie. use another.html.haml instead of application.html.haml)

class applicationcontroller < actioncontroller::base   layout "another"    # way   layout :another_by_method   private   def another_by_method     if current_user.nil?       "normal_layout"     else       "member_layout"     end   end end 

to change actions in controller use layout file

class sessionscontroller < actioncontroller::base   layout "sessions_layout"   # similar case in application controller, assign method instead end 

to change action use other layout file

def my_action   if current_user.nil?     render :layout => "normal_layout"   else     render :action => "could_like_this", :layout => "member_layout"   end end 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -