使用軌3.2和色器件3.2.3我設法設置我的主頁「家#指數」(控制器#動作)作爲做以下修改登錄頁面。
#1新增登錄表單到主頁:
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.button :submit %>
<% end %>
#2添加的方法RESOURCE_NAME,資源和devise_mapping到應用程序/ heldpers/application_helper。RB:
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
#3創建的自定義會話控制器應用程序/控制器/用戶/ sessions_controller.rb:
class Users::SessionsController < Devise::SessionsController
protected
# This method tell sessions#create method to redirect to home#index when login fails.
def auth_options
{ scope: resource_name, recall: 'home#index' }
end
end
#4跳過會話路由和設置定製會話控制器config/routes.rb:
devise_for :users, path: 'auth', skip: [:sessions],
controllers: {
sessions: 'users/sessions'
}
as :user do
get 'auth/sign_in' => 'home#index', as: :new_user_session
post 'auth/sign_in' => 'users/sessions#create', as: :user_session
delete 'auth/sign_out' => 'users/sessions#destroy', as: :destroy_user_session
end
的建議這給我發過一個無限循環,親愛的讀者誰有同樣的問題,答案的下一步是在這裏http://stackoverflow.com/questions/19855866/how-to-set-devise-sign-in-page-as-root-page-in-rails – Jngai1297