[devise] Removing layout from signin view

336 views
Skip to first unread message

Mason Jones

unread,
May 11, 2010, 8:26:07 PM5/11/10
to Devise
This seems like a silly question, but nonetheless... Currently I've of
course customized my signin view, and there's a case when I need it to
render without the layout. Ordinarily this is obviously simple, but
because Devise is handling the process of proceeding to the view, I
don't have a controller in which to specify this, so I'm not really
sure what the best way is to specify that the view should be rendered
without the layout. Any suggestions would be very welcome, and thank
you very much in advance.

Victor Lam

unread,
May 11, 2010, 10:49:36 PM5/11/10
to plataforma...@googlegroups.com
create a custom controller for that. :)

assumed the model you are using with devise is called User

class UsersController < Devise::SessionsController
  layout false
end


--
Victor Lam

Mason Jones

unread,
May 12, 2010, 3:38:38 PM5/12/10
to Devise
Thanks very much -- that is the obvious approach, but I wasn't sure if
there would be a better way to do it or any side effects of extending
the controller. But actually, I tried it and it doesn't seem to
work... The signin page URL is http://localhost:3000/users/sign_in so
it should find it, but it's not. In the log, I see "Processing
SessionsController#new" rather than my controller, which looks like
it's due to the routing. In routes.rb I'm doing the usual
"map.devise_for :users" which I see creates this route:

new_user_session GET /users/sign_in
{:controller=>"sessions", :action=>"new"}

Since that's calling the sessions controller, it's of course not
calling the UsersController. Is it safe to create a custom
SessionsController that extends Devise::SessionsController and just
specifies "layout false"?

I'll try that when I get the chance later and see, but any advice
would certainly be appreciated. Thanks again.

Mason Jones

unread,
May 13, 2010, 12:26:13 PM5/13/10
to Devise
I tried some simple things yesterday, such as simply creating a new

SessionsController < Devise::SessionsController

But that doesn't work because it gets confused about having two
SessionsController
implementations, it seems. With Rails 2.3, is it possible to specify a
different
controller for :sessions and perhaps use that?

It seems that it shouldn't be so difficult to simply control the
layout specification
for the signin page! Unfortunate...

José Valim

unread,
May 13, 2010, 12:30:04 PM5/13/10
to plataforma...@googlegroups.com
If you want to just change the layout, you can always do this:

config.to_prepare {
  SessionsController.layout "omg"
}

Inside your config/environment.rb. It needs to be in a to_prepare callback because it's executed once in production and before each request in development.

Alternatively, if you want to change the layout for all devise controllers, you can do this:

class ApplicationController
  layout :specify_layout

  protected

  def specify_layout
    devise_controller? ? "layout_for_devise" : "layout_for_application"
  end
end

I thought this information was in the wiki. If not, could you please add? Thanks!
--
José Valim

Director of Engineering - Plataforma Tecnologia
Know more about us: http://plataformatec.com.br/en/

Mason Jones

unread,
May 13, 2010, 5:07:04 PM5/13/10
to Devise
Wonderful, thanks very much for the suggestions. Specifying the layout
differently for the devise controllers in that way is a nice way to do
it, and it works perfectly. I appreciate the help. After looking in
the wiki I did find one of these suggestions, which somehow didn't
come up in any of my searches. I edited the wiki to expand the page
and better describe both of these options from you.

Thanks again.

José Valim

unread,
May 13, 2010, 5:08:13 PM5/13/10
to plataforma...@googlegroups.com
Glad to help!
Reply all
Reply to author
Forward
0 new messages