rails动作控制器中未定义的方法“devise_for”
Posted
技术标签:
【中文标题】rails动作控制器中未定义的方法“devise_for”【英文标题】:undefined method `devise_for' in rails action controller 【发布时间】:2011-06-16 05:40:59 【问题描述】:我使用 rails generate devise user 创建了一个模型用户,然后 rake db:migrate 然后 rake routes。一旦我这样做了,我就知道我的主索引中有一个错误是动作控制器异常。说:
undefined method `devise_for' for #< ActionDispatch::Routing::Mapper:0x105371120>
我的完整轨迹是:
config/routes.rb:2
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:233:in `instance_exec'
actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:233:in `draw'
config/routes.rb:1
activesupport (3.0.3) lib/active_support/dependencies.rb:235:in `load'
activesupport (3.0.3) lib/active_support/dependencies.rb:235:in `load'
activesupport (3.0.3) lib/active_support/dependencies.rb:225:in `load_dependency'
activesupport (3.0.3) lib/active_support/dependencies.rb:596:in `new_constants_in'
activesupport (3.0.3) lib/active_support/dependencies.rb:225:in `load_dependency'
activesupport (3.0.3) lib/active_support/dependencies.rb:235:in `load'
railties (3.0.3) lib/rails/application.rb:127:in `reload_routes!'
railties (3.0.3) lib/rails/application.rb:127:in `each'
railties (3.0.3) lib/rails/application.rb:127:in `reload_routes!'
railties (3.0.3) lib/rails/application.rb:120:in `routes_reloader'
activesupport (3.0.3) lib/active_support/file_update_checker.rb:32:in `call'
activesupport (3.0.3) lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
railties (3.0.3) lib/rails/application/finisher.rb:51:in `_callback_before_5'
activesupport (3.0.3) lib/active_support/callbacks.rb:419:in `_run_prepare_callbacks'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:45:in `call'
activesupport (3.0.3) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call'
railties (3.0.3) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.3) lib/rails/application.rb:168:in `call'
railties (3.0.3) lib/rails/application.rb:77:in `send'
railties (3.0.3) lib/rails/application.rb:77:in `method_missing'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.1) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.1) lib/rack/server.rb:213:in `start'
railties (3.0.3) lib/rails/commands/server.rb:65:in `start'
railties (3.0.3) lib/rails/commands.rb:30
railties (3.0.3) lib/rails/commands.rb:27:in `tap'
railties (3.0.3) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
而我的 routes.eb 是:
Kliqq::Application.routes.draw 做 devise_for :用户
get "home/index"
get "welcome/index"
root :to => "home#index"
end
我是否也应该有一个用户控制器或其他东西。谢谢,第一个 rails 应用程序。
【问题讨论】:
是的,我确实运行了 devise:install。我的 gemfile 中也有它 【参考方案1】:我要做的第一件事是尝试重新启动服务器。在重新启动之前,Rails 不会从 gem 加载新方法。
【讨论】:
这实际上帮助我为我解决了同样的问题 - 谢谢 +1 :)以上是关于rails动作控制器中未定义的方法“devise_for”的主要内容,如果未能解决你的问题,请参考以下文章
Laravel 8 中未定义动作 Controller@store 的问题
Rails 3.2:activemerchant 中未定义的方法“class_inheritable_accessor”