【问题标题】:Rails 4 devise sessions controller override routing errorRails 4 设计会话控制器覆盖路由错误
【发布时间】:2016-01-01 12:26:50
【问题描述】:

我已经覆盖了 devise 的会话控制器,但是现在当我尝试在本地 localhost:3000/users/sign_in 中点击此链接时,我遇到了以下错误,

 ActionController::RoutingError (undefined local variable or method `users' for main:Object)      
 app/controllers/users/sessions_controller.rb:1:in `<top (required)>'

到目前为止,我的会话控制器中有这么多代码:

class users::SessionsController < Devise::SessionsController
 before_filter :configure_sign_in_params, only: [:create]

 def new
  super
 end

 def create
  self.resource = warden.authenticate!(auth_options)
  set_flash_message(:notice, :signed_in) if is_navigational_format?
  sign_in(resource_name, resource)
  if !session[:return_to].blank?
   redirect_to session[:return_to]
   session[:return_to] = nil
  else
   respond_with resource, :location => after_sign_in_path_for(resource)
  end
 end

 def destroy
  super
 end


 def configure_sign_in_params
  devise_parameter_sanitizer.for(:sign_in) << :attribute
 end
end

我已经按照这里给出的所有步骤,https://github.com/plataformatec/devise,来覆盖会话控制器

需要帮助!

【问题讨论】:

  • 您可以先将控制器的代码添加到问题中。
  • 从第 1 行开始,因为那是产生错误的地方。
  • 你真的需要包括你的整个会话控制器

标签: ruby-on-rails ruby devise


【解决方案1】:

还有一个问题,Ruby 中的常量以大写字母开头。

Ruby 中的类名是常量,必须以大写字母开头。

users::SessionsController 更改为Users::SessionsController

【讨论】:

    猜你喜欢
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多