gpt4 book ai didi

ruby-on-rails - 设计助手(authenticate_user!,current_user,user_signed_in?)未初始化

转载 作者:行者123 更新时间:2023-12-03 12:29:32 26 4
gpt4 key购买 nike

我正在设置设计,需要能够使用设计助手。
当我将before_filter :authenticate_user!添加到应用程序 Controller 中时,出现以下错误undefined method 'authenticate_user!' for #<HomeController:*>
如果我在自己的家庭(或任何 Controller )中使用skip_before_filter :authenticate_user!并尝试访问该页面,则它不直接存在于我的家庭 Controller 中,而是继承自应用程序 Controller 。

undefined method `user_signed_in?' for #<#<Class *>

它在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" 

因此,似乎它们确实应该由导轨加载。

这是我的应用程序 Controller

class ApplicationController < ActionController::Base

helper :all # include all helpers, all the time
protect_from_forgery
include ActionView::Helpers::NumberHelper
before_filter :authenticate_user!



结束

在安装devise之后,我确实重启了服务器,并多次尝试了不同的尝试来解决该问题。
如果需要更多文件或信息,请告诉我。提前非常感谢您。

编辑:我的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 (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me

end

编辑:整个错误消息

NoMethodError in HomeController#index

undefined method `authenticate_user!' for #< HomeController:0x000000040c45a0 > '



这是完整的痕迹

activesupport (3.2.13) lib/active_support/callbacks.rb:418:in `run_2094683035699451847__process_action_2229546931289158113_callbacks'

activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'

activesupport (3.2.13) lib/active_support/callbacks.rb:385:in >`_run_process_action_callbacks'

activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'

actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'

actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'

actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'

activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'

activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'

activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'

actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'

actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'

actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'

actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'

actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'

actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'

actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'

actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `call'

actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'

actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call'

journey (1.0.4) lib/journey/router.rb:68:in `block in call'

journey (1.0.4) lib/journey/router.rb:56:in `each'

journey (1.0.4) lib/journey/router.rb:56:in `call'

actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call'

warden (1.2.1) lib/warden/manager.rb:35:in `block in call'

warden (1.2.1) lib/warden/manager.rb:34:in `catch'

warden (1.2.1) lib/warden/manager.rb:34:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'

rack (1.4.5) lib/rack/etag.rb:23:in `call'

rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'

rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'

rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'

activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'

activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'

activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `run_177144612565476380_call_4534346825225857812__callbacks'

activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'

activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'

activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'

actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'

railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'

railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'

activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'

railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'

rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'

rack (1.4.5) lib/rack/runtime.rb:17:in `call'

activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'

rack (1.4.5) lib/rack/lock.rb:15:in `call'

actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'

railties (3.2.13) lib/rails/engine.rb:479:in `call'

railties (3.2.13) lib/rails/application.rb:223:in `call'

railties (3.2.13) lib/rails/railtie/configurable.rb:30:in `method_missing'

passenger (4.0.2) lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'

passenger (4.0.2) lib/phusion_passenger/request_handler/thread_handler.rb:135:in `accept_and_process_next_request'

passenger (4.0.2) lib/phusion_passenger/request_handler/thread_handler.rb:106:in `main_loop'

passenger (4.0.2) lib/phusion_passenger/request_handler.rb:449:in `block (4 levels) in start_threads'

passenger (4.0.2) lib/phusion_passenger/utils/robust_interruption.rb:108:in `disable_interruptions'

passenger (4.0.2) lib/phusion_passenger/request_handler.rb:444:in `block (3 levels) in start_threads'



编辑:这是在控制台中运行Devise.helpers的文本。

$ rails console

Loading development environment (Rails 3.2.13)

1.9.3-p429 :001 > Devise.helpers

=> #< Set: {Devise::Controllers::Helpers} >



编辑:这是我的路由rb文件。
:Application.routes.draw做
devise_for :users  

resource :sessions, :only => [:new, :create, :destroy]

devise_scope :user do
match 'signup' => 'users#new', :as => :signup
match 'register' => 'users#create', :as => :register
match '/login' => 'sessions#new', :as => :login
match 'logout' => 'sessions#destroy', :as => :logout
end
match '/activate/:activation_code' => 'users#activate', :as => :activate, :activation_code => nil

match '/users/:id', :to => 'users#show', :as => :user

resources :users do

member do
put :suspend
put :unsuspend
delete :purge
end

end

resource :sessions

other resources

match '' => 'home#index', :as => :home
match ':controller(/:action(/:id))'
root to: 'home#index'
end

最佳答案

确保在您的devise_for :user中添加routes.rb
在这里查看更多:https://stackoverflow.com/a/11180576

关于ruby-on-rails - 设计助手(authenticate_user!,current_user,user_signed_in?)未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16801561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com