Ruby-on-rails rails中未定义的方法“devise_for”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4810941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:12:29  来源:igfitidea点击:

undefined method `devise_for' in rails

ruby-on-railsmethodsdeviseundefined

提问by Yeddie

After I install devise and create a user model. I rake db:migrateand then I rake routes. I then get a error with "undefined method `devise_for' for #". What could be causing this error?

在我安装设计并创建一个用户模型之后。我rake db:migrate然后我rake routes。然后我收到“未定义的方法`devise_for' for #”的错误。什么可能导致此错误?

回答by Serge Paquet

Remember to restart your rails server after installing and configuring devise.

请记住在安装和配置设备后重新启动 Rails 服务器。

回答by Florin

If you have the Devise gem specified in the Gemfile, just make sure you have the following in your routes.rb file:

如果您在 Gemfile 中指定了 Devise gem,只需确保您的 routes.rb 文件中有以下内容:

 devise_for :users

Also, here's a trick to make sure Devise is mapped properly, run: rails c, (the Rails app console) in your app's folder and then the following command line:

此外,这里有一个确保 Devise 被正确映射的技巧,在您的应用程序文件夹中运行:rails c,(Rails 应用程序控制台),然后运行以下命令行:

 Devise.mappings.keys

You should see:

你应该看到:

=> [:user] 

Cheers!

干杯!

回答by vich

Honestly, I would recommend following these two Railscasts (Episode 209and Episode 210). The first is a simple and very easy walkthrough for installing Devise and the second is about customizing it to fit your application.

老实说,我建议关注这两个 Railscast(第 209第 210 集)。第一个是安装 Devise 的简单且非常容易的演练,第二个是关于自定义它以适合您的应用程序。

I've watched both episodes and they drastically helped me with Devise, particularly with the customization.

我看过这两集,他们在设计方面极大地帮助了我,特别是在定制方面。

Your best bet is to start from scratch - you'll learn a heck of a lot and have Devise fully installed and functional.

您最好的选择是从头开始 - 您将学到很多东西,并且 Devise 已完全安装并正常运行。

Hope this helps! Good luck.

希望这可以帮助!祝你好运。

回答by Rishav Rastogi

You may need to do a bundle install

你可能需要做一个 bundle install