Having problem with rake devise:setup - ruby-on-rails

I'm trying to setup devise with putting gem 'devise' , '1.1.2' in gemfile and run sudo bundle install and then I try to run rake --trace devise:setup. Then the error come out , do anyone know what is wrong with my Rails 3 app?
(in /home/wizztjh/work/testing123)
rake aborted!
Don't know how to build task 'devise:setup'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1728:in `[]'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2050:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/var/lib/gems/1.8/bin/rake:19:in `load'
/var/lib/gems/1.8/bin/rake:19

I think the main problem is that you aren't using the appropriate way to install devise. Here are the correct generators per the devise documentation:
#this installs the devise initializer which is needed to run devise in r3.
rails generate devise:install
#this generates your model as a devise resource
rails generate devise [MODEL_NAME]
#this copies all the view files into your local app for modifications
rails generate devise:views

Related

rails aborted "Don't know how to build task 'AdminUser.create!()"

I recently added the gem Active Admin to my rails applicaction (using rails 5.2.6), I got it to work with the default admin and it's working as intended. But I'm unable to add new admins with AdminUser.create!(email: "admin#gmail.com", password: "password", password_confirmation: "password") as I get the rails aborted error and then Don't know how to build task 'AdminUser.create!(email: "admin#gmail.com", password: "password", password_confirmation: "password").
I already tried using rails db:migrate and running my seeds.
Also I am using the devise gem.
Full trace:
rails aborted!
Don't know how to build task 'AdminUser.create!(email: example#gmail.com, password: password, password_confirmation: password)' (See the list of available tasks with `rails --tasks`)
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/task_manager.rb:59:in `[]'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:159:in `invoke_task'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
/var/lib/gems/2.7.0/gems/railties-5.2.6/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/var/lib/gems/2.7.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/var/lib/gems/2.7.0/gems/railties-5.2.6/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/var/lib/gems/2.7.0/gems/railties-5.2.6/lib/rails/command.rb:48:in `invoke'
/var/lib/gems/2.7.0/gems/railties-5.2.6/lib/rails/commands.rb:18:in `<main>'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/var/lib/gems/2.7.0/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/magus/Desktop/Proyecto ing software/grupo-56/bin/rails:9:in `<top (required)>'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
/var/lib/gems/2.7.0/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
/var/lib/gems/2.7.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
/usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
/usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
/home/magus/Desktop/Proyecto ing software/grupo-56/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
As I said before, all the other ActiveAdmin functionalities are working as intended, it's just that I can't create new admins.
What am I doing wrong/could have forgotten to do?
Thanks in advance.
There are several ways to add that admin into the database:
rails console - Just open the console and execute AdminUser.create!(...).
seeds.rb - Open the db/seeds.rb file and paste AdminUser.create!(...). Then run rake db:seed. Note that running rake db:seed multiple times will create that admin multiple times - it's best you have some sort of validations or use AdminUser.find_or_create_by(...) instead.
rake task - create a rake file in lib/tasks, name is not important but it should end in .rake (ex: update.rake)
task :add_admin do
AdminUser.find_or_create_by(email: "admin#gmail.com", password: "password", password_confirmation: "password")
end
Run it with rake add_admin.
If you want that admin only for yourself, your local machine, use the console approach, otherwise pick the other two but make sure the rake tasks are idempotent.

Cant run db:migrate

I trying to deploy my rails 4 application on my ubuntu server, if I run the rake db:migrate command I getting this error
rake aborted!
ArgumentError: invalid byte sequence in UTF-8
My environment:
Rails 4.1.6
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
here the trace
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/file_list.rb:395:in `glob'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/file_list.rb:395:in `glob'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:258:in `block in have_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:256:in `each'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:256:in `have_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:657:in `find_rakefile_location'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:673:in `raw_load_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:94:in `block in load_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:93:in `load_rakefile'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:77:in `block in run'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.1.4/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/root/.rbenv/versions/2.1.2/bin/rake:33:in `<main>'
Any ideas?
On my local machine everything works fine...
What's the data store being used here out of curiosity? Is it possible to just destroy the database and start fresh by chance? If so, you can do that with:
rake db:drop db:create db:migrate

cannot destroy a database using rake

I am new to rails and while practising the tutorials I got the following error. Any ideas..
$ rake destroy scaffold Microposts --trace
rake aborted!
Don't know how to build task 'destroy'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task_manager.rb:49:in `[]'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:115:in `invoke_task'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `load'
/home/keval/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `<main>'
trey rails destroy scaffold Microposts

no such file to load -- "tasks/rails" + rails2 to rails3

I have upgraded rails 2.3.11 to rails 3.0.8 using rails_upgrade plugin. Now I am getting this error and I do not understand why. Any help you can provide is appreciated!
rake aborted!
no such file to load -- tasks/rails
/home/mpn/mpn_admin/branches/to_rails3/Rakefile:13:in `require'
/home/mpn/mpn_admin/branches/to_rails3/Rakefile:13:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:495:in `raw_load_rakefile'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:78:in `block in load_rakefile'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:77:in `load_rakefile'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:61:in `block in run'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `load'
/usr/local/rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `<main>'
Check your RakeFile to make sure it doesn't have the old Rails 2 artifacts left in it. The error is getting thrown in the RakeFile so that's probably the cause and the upgrade plugin would not have caught that.
Here is what a sample Rails 3 RakeFile looks like:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
MyAppNameGoesHere::Application.load_tasks

can't use db:seed in rails

I updated my rails gem to 2.3.5 but I keep getting this error when running db:seed:
$ rake db:seed --trace
(in c:/Documents and Settings/Owner/workspace/thepatstudio)
rake aborted!
Don't know how to build task 'db:seed'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1728:in `[]'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2050:in `invoke_task'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
c:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
c:/Ruby/bin/rake:19:in `load'
c:/Ruby/bin/rake:19
~/workspace/thepatstudio (master)
$ rails --version
Rails 2.3.5
My environment.rb has the correct rails version on it and I also ran rake rails:update. What can I do?
Have you launch the rake task to update your environment after update your gem ?
rake rails:update

Resources