Devise not working with Rails 4.0 - ruby-on-rails

I took the following steps:
rails new routing_test
in Gemfile I added devise
rails devise g user
invoke active_record
create db/migrate/20130731191051_devise_create_users.rb
create app/models/user.rb
invoke rspec
create spec/models/user_spec.rb
invoke factory_girl
create spec/factories/users.rb
insert app/models/user.rb
route devise_for :users
and then, with a simple rake db:migrate, I get the following:
rake aborted!
Rails::Application::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x007feb823b6120 #paths=["/Users/krg07/Developer/core2/test/dummy/config/routes.rb", "/Users/krg07/Developer/core2/config/routes.rb"], #route_sets=[#<ActionDispatch::Routing::RouteSet:0x007feb82c5e700>, #<ActionDispatch::Routing::RouteSet:0x007feb82d34440>]>
/Users/krg07/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:10:in `rescue in execute_if_updated'
/Users/krg07/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
/Users/krg07/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
Any idea what is going on? Thanks, really appreciate it!

I had problems getting Devise to work with Rails 4 and found that most of the issues were because I was including an older version of the gem that was not updated to work with Rails 4. Specifying the latest version of the gem helped:
gem 'devise', '3.0.0'
You may need to re-run the Devise installer after the gem has been updated.

You are not the only one to have this problem, see the following issue for more informations.

Related

Devise Security Extension

I'm trying to use devise security extension as it has the exact methods I'm looking for for my project.
I've followed all the instructions on the github page: https://github.com/phatworx/devise_security_extension, but when I try to run my project I get this error message:
/home/felipe/ruby-example-2.4.1/ball-consulta-de-notas-fiscais/vportal/config/initializers/devise.rb:285:in block in <top (required)>': undefined methodexpire_password_after=' for Devise:Module (NoMethodError)
I've added the method :password_expirable to my user.rb and uncommented the line # Should the password expire (e.g 3.months)
config.expire_password_after = 2.months on my devise.rb
I'm running rails 5.0.
Can you please help me?
You don't have devise_security_extension in your Gemfile.lock, also there is no gem 'devise' in your Gemfile as well.
So, just add two lines gem 'devise' and gem 'devise_security_extension' to your Gemfile. Then repeat actions from documentation:
Devise
Devise Security Extension
Hope this will help you!

Problems with Rails Girls Guides's Adding Authentication with Devise

I'm very new to Rails, and I'm trying to build a user authentication system with 'devise', but I am failing. I'm following Rails Girls Guides's tutorial on adding authentication using the gem 'devise'. Once I got to step 5, which is to set up the User model, I received this error after running rake db:migrate
rake aborted!
NoMethodError: undefined method `merge!' for #<ActionDispatch::Routing::Mapper::Scope:0x007fd3397a7448>
/Users/.rvm/gems/ruby-2.1.2/gems/devise-3.0.4/lib/devise/rails/routes.rb:420:in `ensure in with_devise_exclusive_scope'
/Users/.rvm/gems/ruby-2.1.2/gems/devise-3.0.4/lib/devise/rails/routes.rb:420:in `with_devise_exclusive_scope'
/Users/.rvm/gems/ruby-2.1.2/gems/devise-3.0.4/lib/devise/rails/routes.rb:233:in `block (2 levels) in devise_for'
/Users/.rvm/gems/ruby-2.1.2/gems/devise-3.0.4/lib/devise/rails/routes.rb:336:in `block in devise_scope'
Has anyone solved this error? I've looked at all solutions such as not generating user model before installing devise, running bundle install, running rails g devise:install, and more. Nothing has worked so far when I'm trying to use devise for Rails 4.0.
Also, does anyone have recommendations on what tutorials I can follow to build an authentication system? I've tried a lot so far, and none has worked.
This looks to be a know bug with prior 3.4.0 devise.
Upgrading it should make this error go away.
To do that edit your Gemfile where you have gem "devise" <might have some other stuff in front> and change it to gem "devise", '~> 3.4.1'
then run bundle update devise and you are done.

RoR using Devise - Encrypted Password

Hi pardon my ignorance but I'm new to RoR. My problem is that I'm trying to make my Devise gem work but when I fill out the information and click Sign-Up, I get this in return: "undefined method `encrypted_password=' for".
I've already tried rake db:migrate and also clearing the attributes in the User.rb model but still it doesn't work.
Please any guidance would be appreciated!
This most likely means, that you are missing on migrations.
Are you sure, that you have setup devise right?
https://github.com/plataformatec/devise
rails generate devise:install
rails generate devise User
bundle exec rake db:migrate
In the rails console run, this will tell you if the migration has run
User.new.respond_to?(:encrypted_password=)
This should return true, if not do
bundle exec rake db:migrate:reset
In the site railscasts.com you can watch:
http://railscasts.com/episodes/209-introducing-devise
after that you understand where you make a mistake
If you then get an error - write comments and we help
P.S. gem 'devise', '1.1.rc0' => gem 'devise' in gemfile

Devise issue Ruby on rails

I'm trying to get Devise working. I'm following this tutorial which tells me to do "rails generate devise User" but when I do that command, it gives me an error saying
"NameError: uninitialized constant User from /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'"
What am I doing wrong? I'm using Rails 3.0.9, Ruby 1.8.7 and Ubuntu 11.04
Thanks a bunch in advance,
Michael.
Do you have gem devise in your Gemfile? Then, run bundle install. You can also try putting require 'devise' in your config/application.rb file (but you shouldn't have to do this).

rake spec not using the rails environment

I'm attempting to use rspec in a rails project I've just upgraded to rails 2.3.2. I've installed rspec 1.2.6 and rspec-rails 1.2.6 as plugins in the app.
My problem is the specs don't have access to my app classes or any of the rails standard libraries.
First I had to specify the model class I want to test by using the full path from RAILS_ROOT but now as it loads the class I get the following
/app/models/person.rb:1: uninitialized constant ActiveRecord (NameError)
from ./spec/models/person_spec.rb:1:in `require'
from ./spec/models/person_spec.rb:1
from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:15:in `load'
from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:15:in `load_files'
from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:14:in `each'
from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:14:in `load_files'
from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/options.rb:99:in `run_examples'
from /Users/law/Projects/roster/vendor/plugins/rspec/lib/spec/runner/command_line.rb:9:in `run'
from /Users/law/Projects/roster/vendor/plugins/rspec/bin/spec:4
rake aborted!
I am launching rspec by calling rake spec from the root of the application.
Any ideas on what might be missing in this situation?
you need indeed include the spec_helper.rb in every spec file you write....
You can run individual specs that way:
$ spec specs/models/person_spec.rb
instead of always running the whole spec suite
I havn't used spec, so this may not solve your problem, but if you're writing your own rake task and need your rails environment, you have to ask for it.
task(:task_name => :environment) do
# Task Implementation Here
end

Resources