如何使用devise和Rails 4设置用户身份验证? [英] How do I set up user authentication using devise and Rails 4?

查看:134
本文介绍了如何使用devise和Rails 4设置用户身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图按照 RailsGirls文章,但在创建简单的新项目之后,添加 gem'devise'并运行 bundle install ,但是当我运行 rails生成devise:install 我收到一个错误开始

 错误:获取可用的生成器脚本执行错误:
错误:C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/ 1.9.1 / gems / activerecord-4.1.1 / lib / active_record / dynamic_matchers.rb:26:在`method_missing'中:用于用户的未定义方法`devise'(调用'User.connection'建立连接):Class(NoMethodError )

有谁知道我可能做错了什么? (我尝试使用devise wiki中的说明,但是我也不能这样做)。

解决方案

我刚刚遇到了同样的问题,这是因为您尝试在尝试安装设计之前尝试生成该模型。 b

将用户模型的更改保存(或删除)和任何迁移文件,然后运行这个

  rails generate devise:install 
pre>

在此之后,您可以卸载并应用迁移,它应该可以正常运行。


I'm trying to get user authentication with devise working, and failing.

I tried following the steps in the RailsGirls article, but after creating the simple new project, adding the gem 'devise' and running bundle install, but when I run rails generate devise:install I get a screenful of errors starting

Error:Get available generators script executes with errors:
Error:C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `devise' for User (call 'User.connection' to establish a connection):Class (NoMethodError)

Has anybody any idea what I might be doing wrong? (I tried using the instructions in the devise wiki, but I couldn't get it working that way either).

解决方案

I just ran to this same problem today, it's because you tried to generate the model before you tried to install devise it self

Stash ( or remove ) the changes for the user model and any migration file, then run this

rails generate devise:install

after that unstash and apply the migration, it should work just fine.

这篇关于如何使用devise和Rails 4设置用户身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆