I am using a common layout file for all my application pages. But I want to include a different layout for only the sign_in
page. How can I achieve it?
Asked
Active
Viewed 252 times
-1
-
1also you have to just add app/layouts/devise.html.haml for devise layout, no need to override any controller. – Sanket Jun 24 '14 at 05:30
-
possible duplicate of [different layout for sign\_in action in devise](http://stackoverflow.com/questions/4982073/different-layout-for-sign-in-action-in-devise) – Brad Werth Jun 24 '14 at 06:21
2 Answers
3
try this out:
suppose you have a sessions controller for sign_in action
here 'other_layout' is a layout in app/views/layouts directory
class SessionsController < ApplicationController
layout "other_layout", only: [:sign_in]
def sign_in
end
end

Sachin Singh
- 7,107
- 6
- 40
- 80
0
Devise
If you're using Devise
(which is unlikely juding by your question, but will be of interest to someone anyway) - you may want to make use of the devise_controller?
helper
You can use it like this:
#app/controllers/application_controller.rb
Class ApplicationController < ActionController::Base
layout :set_layout
private
def set_layout
devise_controller? ? "devise" : "application"
end
end

Richard Peck
- 76,116
- 9
- 93
- 147
-
1Thanks Rich it worked on login page. But when I opened the home page of my application.It show the error Missing template layouts/login can you tell me what I did wrong ? – Randhir Jun 24 '14 at 06:27
-
Hmmmmmmm interesting. Are you still any other layout methods to set the layout individually? Also, when you mention you're using the `sign_in` action - is this a custom action you created, or your terminology for the `create` action of `Sessions¬ controller? – Richard Peck Jun 24 '14 at 06:33
-
I have two layout files inside /views/layout one is application.html.erb and other is devise.html.erb. – Randhir Jun 24 '14 at 06:38
-
Okay, but this will not explain the error - the application is trying to call `layouts/login.html.erb` - we need to know why & where – Richard Peck Jun 24 '14 at 06:43
-
-
1Hey Rich, I think if you want to do like above, just 'create layout/devise.html.erb' file, device will automatically pick this as a layout for devise controllers. – Sanket Jun 26 '14 at 13:31