Rails 4 Generate Devise Views - ruby-on-rails

I'd like to generate some devise views for an application, but whenever I try to use the command rails g devise:views, I get a complex error, well above my understanding.
/Users/michaeldunnegan/.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': Rails::Application::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x007ff613f5bb10 #paths=["/Users/michaeldunnegan/projects/SoundShare/config/routes.rb"], #route_sets=[#<ActionDispatch::Routing::RouteSet:0x007ff6168369e0>]> (RuntimeError)
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/michaeldunnegan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /Users/michaeldunnegan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /Users/michaeldunnegan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /Users/michaeldunnegan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /Users/michaeldunnegan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /Users/michaeldunnegan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /Users/michaeldunnegan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/michaeldunnegan/projects/SoundShare/config/environment.rb:4:in `<top (required)>'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
from /Users/michaeldunnegan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:45:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
One of these lines, /Users/michaeldunnegan/projects/SoundShare/config/environment.rb:4:in'`
is interesting. All I have in that file is:
# Load the Rails application.
require File.expand_path('../application', __FILE__)
SoundShare::Application.initialize! # this is the line

make sure you have the devise gem compatible with rails 4 gem 'devise', '~> 3.0.0.rc' #or higher
run bundle update
Remove devise.rb in initializers, then run devise:install again to install new configs in intializers.
make sure you run devise model generator, for example rails g devise User
now you should be able to run: rails g devise:views
Edit
After working in teamviewer on Mike's computer, we took a copy of devise.rb from a working project on rails 4 and place it in config/initializers/
Next we ran the rails generate devise:install command and it said something back about a deprecation and asked us if we want to replace the content of devise.rb file. We accepted it and after this all devise commands worked well.

Related

There was an error while trying to load the gem 'rails-api'. (Bundler::GemRequireError)

I am working with Rails 5.0.0.beta3 and creating a rails-api. when i run
rails-api generate scaffold user email:string password:string auth_token:string
it shows the error
.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'rails-api'. (Bundler::GemRequireError)
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
from /home/ahsanul/Documents/rails-api/my_blog/config/application.rb:7:in `<top (required)>'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:82:in `require'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:82:in `preload'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:143:in `serve'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:131:in `block in run'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:125:in `loop'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application.rb:125:in `run'
from /home/ahsanul/.rvm/gems/ruby-2.2.3/gems/spring-1.7.1/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/ahsanul/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ahsanul/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
How can i resolve the problem?
You don't need to include rails-api gem in your Rails 5 app's Gemfile. It's already merged into Rails 5.
Reference
I tried all the above suggestion from Babar but didn't work, so i tried one little thing that work which is adding gem 'listen' to the gem file.
it works for me!!
rails-api generate scaffold user email:string password:string auth_token:string
No need of writing rails-api, just use rails. Rails::API has been merged into Rails 5.0, so no need of gem 'rails-api'.So remove it from gemfile.After than you may get error when you try to migrate.So you have to include listen gem.

Getting error with ancestry gem

I am trying to add ancestry to an Event_Tags model that I have. Right now that model only has a name. I added 'ancestry' to the gemfile and bundled. Now when I go to run the following command:
rails g migration AddAncestryToEventTags ancestry:string
I get the following error:
/Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/ancestry- 2.0.0/lib/ancestry/has_ancestry.rb:7:in `block in has_ancestry': Unknown option for has_ancestry: :hierarchy_class_name => "TagHierarchy". (Ancestry::AncestryException)
Not sure why why this is coming up. I have been following the Ancestry railscast episode as well as the documentation.
This is also the same error I am getting when simply trying to run the rails console.
Here is the entire message:
/Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/ancestry-2.0.0/lib/ancestry/has_ancestry.rb:7:in `block in has_ancestry': Unknown option for has_ancestry: :hierarchy_class_name => "TagHierarchy". (Ancestry::AncestryException)
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/ancestry-2.0.0/lib/ancestry/has_ancestry.rb:5:in `each'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/ancestry-2.0.0/lib/ancestry/has_ancestry.rb:5:in `has_ancestry'
from /Users/stevenbrooks1111/Code/freelance/GRN-Auth/config/initializers/tag_patch.rb:3:in `<class:Tag>'
from /Users/stevenbrooks1111/Code/freelance/GRN-Auth/config/initializers/tag_patch.rb:2:in `<module:ActsAsTaggableOn>'
from /Users/stevenbrooks1111/Code/freelance/GRN-Auth/config/initializers/tag_patch.rb:1:in `<top (required)>'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/engine.rb:587:in `each'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/engine.rb:587:in `block in <class:Engine>'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/stevenbrooks1111/Code/freelance/GRN-Auth/config/environment.rb:14:in `<top (required)>'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/application.rb:103:in `require_environment!'
from /Users/stevenbrooks1111/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.11/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
One possible reason, which in my case was true, there are two different engines using ancestry and acts_as_tree.
Engine1, requires ancestry in gemspec.
Engine2, requires acts_as_tree in gemspec.
If engine1 is placed above engine2 in gemfile, ancestry gem is loaded first. In which case, this code executes and overrides acts_as_tree function. One way to fix this is put Engine2 over Engine1 in gemfile.
I haven't been able to figure out a better way to fix this, please let me know if you become aware of any.

"rails g devise install" instead of "rails g devise:install" in rails4?

In my newly created Rails 4 app, I suddenly hit rails g devise install instead of rails g devise:install. After this mistake, devise components for install are generated as I understood from this output:
invoke active_record
create db/migrate/20130921224627_devise_create_installs.rb
create app/models/install.rb
insert app/models/install.rb
route devise_for :installs
When I try to roll it back like rails d migration install, it failed because of not being set config.secret_key in devise.rb, but there was no file named it, too. I can't run rails g devise:install even creating devise.rb file and adding secret key configuration. After this process, here's another error occured:
/home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:10:in `rescue in execute_if_updated': Rails::Application::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x007f6c66a67848 #paths=["/home/ekrem/workspace/contactman4/config/routes.rb"], #route_sets=[#<ActionDispatch::Routing::RouteSet:0x007f6c66ac1c80>]> (RuntimeError)
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/ekrem/workspace/contactman4/config/environment.rb:5:in `<top (required)>'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
from /home/ekrem/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:45:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
How can I correct this mistake?
There're couple ways around that, but I prefer to just remove everything that generator created.
the migration
the model
the route
I don't see you running the rake db:migrate command, so the migration might not be commited. If it is , run rake db:rollback wich will rollback the last migration.
One last thought for you. You should really learn how to use Git (or any other VCS you prefer). 'Cause it's exactly on of the problems that a VCS is designed to solve.

Error running rails generate devise User

Hey I am new to rails and I am getting this error whenever I try to run
rails generate devise User
I get this error in there terminal:
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application/routes_reloader.rb:10:in `rescue in execute_if_updated': Rails::Application::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x007fcad64c5e20 #paths=["/Users/DavidStevenson/Desktop/omrails/omrails/config/routes.rb"], #route_sets=[#<ActionDispatch::Routing::RouteSet:0x007fcad64c5d80>]> (RuntimeError)
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/initializable.rb:30:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:180:in `each'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application.rb:215:in `initialize!'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/DavidStevenson/Desktop/omrails/omrails/config/environment.rb:5:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `block in require'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:213:in `load_dependency'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application.rb:189:in `require_environment!'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/commands.rb:47:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I have looked in the routes.rb file and could not see anything apparently wrong. When I comment out the line:
devise_for :installs
I can run the server again. Any thoughts why this would happen?
Firstly, why do you use ruby 1.9.3 instead of 2.0 ?
Secondly, why do you use rails 4.0.0.rc2 instead of its stable release 4.0 ?
For your question,
devise requires devise_for :users in your routes.rb file. It must be same as your resource name. Use user both in routes.rb and at your generator.
I found this error after migrating from Active Record to MongoID, the problem is that the Devise initializer (config/initializers/devise.rb) specifies the ORM (line 25 for me):
require 'devise/orm/active_record'
I just only needed to replace this line with:
require 'devise/orm/mongoid'
Now is working :)

Uninitialized constant error message after a typo done while installing devise gem

I just started learning how to program, but have been using Ubuntu for some years now, so I am well familiar with researching problems and errors, but either this area is too new for me, or I really cant find any specific answers for this.
I am taking a ruby on rails introduction course, and got to the point where I had to install the devise gem and here is where I made a mistake.
While following the instructions on the devise github page I accidentally typed in:
rails generate devise install
instead of
rails generate devise:install
Now, whenever I try to load
rails s
I get this error message:
/home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:230:in `block in constantize': uninitialized constant Install (NameError)
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:229:in `each'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:229:in `constantize'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise.rb:256:in `get'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:77:in `to'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:72:in `modules'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:89:in `routes'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:156:in `default_used_route'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:66:in `initialize'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise.rb:290:in `new'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise.rb:290:in `add_mapping'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/rails/routes.rb:208:in `block in devise_for'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/rails/routes.rb:207:in `each'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/rails/routes.rb:207:in `devise_for'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config/routes.rb:3:in `block in <top (required)>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:260:in `draw'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config/routes.rb:1:in `<top (required)>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `each'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/file_update_checker.rb:78:in `call'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/file_update_checker.rb:78:in `execute'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:27:in `updater'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config/environment.rb:5:in `<top (required)>'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config.ru:4:in `block in <main>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config.ru:1:in `new'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config.ru:1:in `<main>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands/server.rb:46:in `app'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands/server.rb:70:in `start'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Before posting here I tried reinstalling ruby 1.9.3. using rvm. I tried using
rvm gemset empty [gemset_name]
as was discribed in RVM: Uninstalling all gems of a gemset but that didn't really help either.
What should I do? Can anyone explain to me what is happening here?
I understood your problem.
You have written rails generate devise install. It means that you have associated install as a model to devise rather configure it. So your files have been created with out devise configuration.
You just follow what I have written:
1) Create a devise.rb file in '/config/initializers'
2) Write the following code inside it:
Devise.setup do |config|
config.mailer_sender = "devise#example.com"
config.scoped_views = true
require 'devise/orm/active_record'#[This works for you]
config.case_insensitive_keys = [ :email ]
config.strip_whitespace_keys = [ :email ]
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 10
config.reconfirmable = true
config.reset_password_within = 6.hours
config.sign_out_via = :delete
end
2) And write rails destroy devise install in the terminal. Thats it.
I think the above will work for sure.
3) Now start your server again rails s.
4) Install devise again carefully. And go ahead.
I don't think you have a gem problem, just a confused Devise setup, which is likely easily unconfused.
When you run the Devise generator (with rails generate Devise:something) it runs code to create a few files specific to your application within your application tree (app/*). I am looking at a Devise install and think it's mostly going to be in the app/views/devise directory, but it's possible that it also updates your User model. It definitely updates your app/routes.rb file and creates a file in config/initializers. There may be others.
Delete any of these. There may be other files in locales, db/migrate (there is a migration -- don't run it, or run rake db:rollback before deleting it if you have).
Then re-run the installation.
Another approach if this doesn't work would be to create a new dummy Rails app, install devise there, and see what files get created -- usually generators report what they are doing.

Resources