相关疑难解决方法(0)

Devise Helpers(authenticate_user!,current_user,user_signed_in?)未初始化

我正在设置设计,需要能够使用设计助手.当我添加 before_filter :authenticate_user!到应用程序控制器时,我收到以下错误undefined method 'authenticate_user!' for #<HomeController:*>

它不是直接存在于我的家庭控制器中,而是从应用程序控制器继承,如果skip_before_filter :authenticate_user!我在家中(或任何控制器)使用并尝试访问该页面,我会收到以下错误.

undefined method `user_signed_in?' for #<#<Class *>
Run Code Online (Sandbox Code Playgroud)

它打破了调用它的layouts/application.html.erb文件中的行.任何助手都会发生同样的事情.但是,当我加载rails控制台并输入$LOAD_PATH.dup包含的输出时,它看起来好像根本没有被加载

 "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib", "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/app/controllers", "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/app/helpers", "/usr/local/rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/app/mailers" 
Run Code Online (Sandbox Code Playgroud)

所以看起来它们确实应该由rails加载.

这是我的应用程序控制器

class ApplicationController <ActionController :: Base

helper:all
#include all helper,protect_from_forgery一直
包括ActionView :: Helpers :: NumberHelper
before_filter:authenticate_user!

结束

我在安装设备后重新启动了服务器,并且多次尝试不同的尝试来解决问题.如果需要更多文件或信息,请告诉我.非常感谢你提前.

编辑:我的user.rb文件被要求显示我确实安装了devise

class User < ActiveRecord::Base

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :encryptable, :encryptor => :restful_authentication_sha1  

  # Setup accessible …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise ruby-on-rails-3

19
推荐指数
2
解决办法
2万
查看次数

Rails/Devise登录在Safari上不起作用(422/CSRF错误)

登录在Chrome上运行正常,但在Safari(或我假设其他Webkit浏览器)上不起作用.登录后我收到此错误消息("您想要的更改被拒绝.也许您尝试更改了您无法访问的内容."):

你想要的改变被拒绝了. 也许你试图改变一些你无法访问的东西.

根据我的heroku日志,这就是发生的事情:

2016-12-07T14:14:23.778153+00:00 app[web.1]: Can't verify CSRF token authenticity
2016-12-07T14:14:23.778899+00:00 app[web.1]: Completed 422 Unprocessable Entity in 2ms (ActiveRecord: 0.0ms)
2016-12-07T14:14:23.785544+00:00 app[web.1]:
2016-12-07T14:14:23.785547+00:00 app[web.1]: ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
Run Code Online (Sandbox Code Playgroud)

我相信我正在发送正确的CSRF令牌,但似乎有些事情发生了故障.这是我目前的application_controller.rb:

class ApplicationController < ActionController::Base


  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  after_action :flash_to_headers

  # this is so that json requests don't redirect without a user
  before_action :authenticate_user!
  # before_action :authenticate_user!, unless: request.format == :json
  # before_action :user_needed, if: …
Run Code Online (Sandbox Code Playgroud)

safari ruby-on-rails csrf devise

12
推荐指数
1
解决办法
1750
查看次数

什么是设计authenticate_user的代码!生成后:用户

我认识到,authenticate_user!没有明确定义在宝石的文件,但我想知道的典型应用(命名型号认证User),将方法是什么样子.我需要知道,以便我可以稍微修改它.

ruby-on-rails devise

5
推荐指数
1
解决办法
6804
查看次数

标签 统计

devise ×3

ruby-on-rails ×3

csrf ×1

ruby-on-rails-3 ×1

safari ×1