设计在登录时不重定向到根路径

时间:2017-09-30 23:16:27

标签: ruby-on-rails devise ruby-on-rails-5

不确定原因,但是在成功登录后,Devise不会重定向到我的根路径。

我将通过:authenticate_user!重定向到登录页面,但当我成功登录时,只需刷新登录页面即可。如果我然后刷新页面,我将被带到根页面。据我所知,我对此并不奇怪,只是一个爱好应用程序的基本设置。

的routes.rb

Rails.application.routes.draw do
  resources :feature_documents
  get 'pages/profile'
  resources :memberships
  devise_for :users
  mount Ckeditor::Engine => '/ckeditor'
  resources :phases
  resources :tasks
  resources :features
  resources :projects
  root to: 'pages#home'
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

application_controller.rb

class ApplicationController < ActionController::Base

  protect_from_forgery with: :exception

  before_action :set_breadcrumbs
  before_action :configure_permitted_parameters, if: :devise_controller?
  before_action :masquerade_user!
  before_action :set_projects

  layout :layout_by_resource

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :role, :title])
    devise_parameter_sanitizer.permit(:account_update, keys: [:name, :role, :title])
    # Invitable parameters
    # added_attrs = [:username, :email, :password, :password_confirmation, :remember_me]
    # devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
    # devise_parameter_sanitizer.permit :account_update, keys: added_attrs
    # devise_parameter_sanitizer.permit :accept_invitation, keys: [:email]
  end

  def set_breadcrumbs
    add_breadcrumb "Home",     root_path
    add_breadcrumb "Projects", projects_path
    add_breadcrumb "Phases",   phases_path
    add_breadcrumb "Features", features_path
    add_breadcrumb "Tasks",    tasks_path
  end

  private

  def layout_by_resource
    if devise_controller?
      "auth"
    else
      "application"
    end
  end

  def set_projects
    @projects = Project.all
  end
end

pages_controller.rb

# This controller is responsible for serving up the static pages for the application
class PagesController < ApplicationController

  before_action :authenticate_user!

  # GET /
  def home
  end

  # GET /profile
  def profile
  end
end

在控制台中我看到了POST,但它只是重新定向到登录页面。

我已经使用了Devise,不太确定为什么即使登录成功,这也不会在登录后重定向到根路径。如果有人能够对这个问题有所了解,我们将不胜感激。

0 个答案:

没有答案