0
votes

I've created in my app devise in scope

scope '/business' do
    devise_for :accounts, :controllers => { :sessions => "business/sessions" }
  end
  namespace :business do
    root to: 'user_profiles#index'
    resources :user_profiles
  end

Saved devise templates to business/sessions (ex business/sessions/sessions/new.erb) and wrote business/sessions controller

class Business::SessionsController <
  Devise::SessionsController
layout: 'temp'
  def after_sign_in_path_for(resource)/
    "/business"
  end

  def after_sign_out_path_for(resource)
    '/business'
  end
end

but when i enter url and is send to login, i see in logs:

Rendered devise/sessions/new.html.erb within layouts/application (94.7ms) 

So - not layout and not custom view.
How can i tell devise to use custom layout & views?

Update 1
For views - they should be placed into the directory of the corresponding model ex: views/accounts/sessions/

1
I'm not seeing new method on class Business::SessionsController, sessions_controller.rb - rails_id
what do you mean a parent? you have tried my answer? - rails_id
class Business::SessionsController < Devise::SessionsController parent is Devise::SessionsController - Elmor
You want custom views devise, you should add new and create action method to your custom controller, if controller in /business/sessions_controller.rb you should add view in /business/sessions/ folder. Again, have you tried my answer? if my answer not works, you can tell me error and I will update my answer. - rails_id

1 Answers

2
votes

Try this :

 # routes.rb

 devise_for :accounts, :except => [:sessions]

  scope '/business' do
    devise_scope :account do
      get '/login' => 'sessions#new', :as => :new_account_session
      post '/process' => 'sessions#create', :as => :account_session
      delete '/logout' => 'sessions#destroy', :as => :destroy_account_session
    end
  end

If you want customize devise session,

Any of the logic within that controller that you want to override you can override by calling that method and inserting your own logic. For the list of what's in that controller, you can view the code on their Github page. If you do not wish to override their methods you can either leave them out, or just call super.

example :

def new
 super
end

So, I suggestion for call super on new, create and destroy action from this sessions_controller.rb, customize controller, looks like :

  # bussiness/sessions_controller.rb

   class Business::SessionsController < Devise::SessionsController
     layout 'temp'

     def new
      super
     end

     def create
      super
     end

     def destroy
       super
     end
   end

And after_sign_in_path_for and def after_sign_out_path_for you can put into applocation controller looks like :

   # application_controller.rb

   class ApplicationController < ActionController::Base
   protect_from_forgery

     def after_sign_in_path_for(resource)
      business_path
     end

     def after_sign_out_path_for(resource)
      business_path
     end
  end

And view business/sessions/new.erb

http://localhost:3000/business/login for login