Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use different layout for different pages in ruby on rails?

i know application.html.erb is the default for every page .i want to use a different layout when user login .i mean the dashboard after login should be of different layout rather than the default one(application.html.erb).

like image 296
shalini sharma Avatar asked Apr 01 '15 14:04

shalini sharma


2 Answers

Create new layout eg app/views/layouts/dunno.html.erb. Use in controller

class DashboardController < ApplicationController
  layout 'dunno'
end

or per action

class DashboardController < ApplicationController
  def index
    render layout: 'dunno'
  end
end

see docs for details

like image 177
lisowski.r Avatar answered Nov 15 '22 06:11

lisowski.r


You can do this in application controller, add this code, I am assuming that you are using devise

layout :layout_by_resource

def layout_by_resource
  user_signed_in? ? "my_custom_layout" : "application"
end
like image 40
Rajdeep Singh Avatar answered Nov 15 '22 05:11

Rajdeep Singh