0

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/

4

1 回答 1

2

尝试这个 :

 # 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

如果您想自定义设计会话,

该控制器中您想要覆盖的任何逻辑都可以通过调用该方法并插入您自己的逻辑来覆盖。有关该控制器中内容的列表,您可以在他们的 Github 页面上查看代码。如果您不想覆盖他们的方法,您可以将它们排除在外,或者直接调用 super。

例子 :

def new
 super
end

所以,我建议调用 super on new, create and destroy action from this sessions_controller.rb,自定义控制器,看起来像:

  # bussiness/sessions_controller.rb

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

     def new
      super
     end

     def create
      super
     end

     def destroy
       super
     end
   end

而且after_sign_in_path_fordef after_sign_out_path_for可以将应用程序控制器放入如下所示:

   # 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

并查看business/sessions/new.erb

http://localhost:3000/business/login用于登录

于 2013-07-04T17:08:30.757 回答