I am new to Ruby on Rails and am trying to make my first application. I am having issues though anytime I run any rails generate
command. I get the following er
Execute this following commands:
rails generate devise:install
rails generate devise MODEL
If devise is installed already and also generated devise model as above and still facing error.
Add this code to User.rb
file in Models
class User < ApplicationRecord
extend Devise::Models
rails g devise install
!= rails g devise:install
I ran into this problem as well.
Executing rails generate devise install
(sic!) there was nothing that seemed not to have worked. The terminal output was:
$ rails g devise install
Running via Spring preloader in process 5422
invoke active_record
create db/migrate/20180306165306_devise_create_installs.rb
create app/models/install.rb
insert app/models/install.rb
route devise_for :installs
But I missed the semicolon. Reverting these changes and then executing rails generate devise:install
(note the :
between devise
and install
), everything worked out perfectly. Also you get a much more extensive output:
$ rails g devise:install
Running via Spring preloader in process 5218
create config/initializers/devise.rb
create config/locales/devise.en.yml
===============================================================================
Some setup you must do manually if you haven't yet:
1. Ensure you have defined default url options in your environments files. Here
is an example of default_url_options appropriate for a development environment
in config/environments/development.rb:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
In production, :host should be set to the actual host of your application.
2. Ensure you have defined root_url to *something* in your config/routes.rb.
For example:
root to: "home#index"
3. Ensure you have flash messages in app/views/layouts/application.html.erb.
For example:
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
4. You can copy Devise views (for customization) to your app by running:
rails g devise:views
===============================================================================
I ran into a similar problem with an existing project freshly checked out from a repo:
The specific missing files were:
config/initializers/devise.rb
config/locales/devise.en.yml
In this case, because the devise.rb
was in the .gitignore
list there was a config/initializers/devise.rb.example
file that could be copied over.
Or, like me, after adding:
gem 'devise'
to Gemfile, and running:
$ bundle install
you forgot to restart the server with Ctrl C and:
$ rails s
This is the appropriate Order.
gem 'devise'
Run the bundle command to install it.
rails generate devise:install
rails generate devise MODEL
Here Model was created before the "rails generate devise:install".So you have to go back an comment everything that model created :
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
#devise :database_authenticatable, :registerable,
#:recoverable, :rememberable, :trackable, :validatable
end
and also this
Rails.application.routes.draw do
#devise_for :users
end
Now,Run "rails generate devise:install" and after that uncomment the above .
Running rails generate devise:install
creates a config/initializers/devise.rb
file.
You have to restart your server with Ctrl + C
and rails s
in order for a change in config
file to take effect.
Otherwise you'll get the same error upon refreshing the page.