Ask A Question

Notifications

You’re not receiving notifications from this thread.

Layout for Devise with scoped route

Nick McNeany asked in Rails

Hey Everyone,

I'm trying to use a custom layout for my devise/registrations#edit view. I'm using a scoped route.

devise_scope :member do
        get "/members/:id/settings" => "devise/registrations#edit", as: "edit_member_registration"
end

I call the layout in my registrations controller layout "member_area", only: :edit, but it's not showing.

I have a feeling it has to do with the scoped route. Also, if I take off the only: :edit the layout shows up on the other registration pages as expected.

Anyone have any thoughts on this?

Thanks for any help!

Nick

Reply

Hey Nick,

I'm still a bit foggy on devise and the routes, so this may not be the best way, but I had to do a similar setup where each user type had their own layout for the various devise functions and this is what has been working for that project:

devise_for :members, controllers: { registrations: 'members/registrations'}, :path => '', :path_names => {:sign_in => 'member_login', :sign_up => 'member_signup'}

Then for the views, you'll have a structure similar to this:

  • views
    • members
    • registrations
      • edit
      • new

And your controllers like:

  • controllers
    • members
    • registrations_controller.rb

Would love for someone with more expertise to chime in if there's a better way!

Reply

Hey Jacob,

Thanks for the help! Unfortunately I still can't get the layout to display. I think I'm just going to move onto plan b for now.

I really appreciate your help!

Nick

Reply

Doh, well sometimes that's how it goes until we have more time!

Something I forgot to mention in my original post was that the registrations_controller.rb doesn't need any layout specified, you just need to make sure to namespace the controller...

class Members::RegistrationsController < Devise::RegistrationsController

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 78,890+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.