I am currently writing a website with Ruby on rails for a few months.
Suddenly (5 or 6 days ago), all the commands like rails db:migrate, rails db:rollback, rails db:*" don't work anymore (and it does not seem to have touched anything...).
I tried to reinstall the gems rake, rails and railsties (which were already in their latest versions) but the problem still persists.
My Gemfile
The result when I execute the command rails db:migrate:
rails aborted!
Don't know how to build task 'db:migrate' (See the list of available tasks with `rake --tasks`)
/usr/local/rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/usr/local/rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/command.rb:48:in `invoke'
/usr/local/rvm/gems/ruby-2.5.1/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
The result when I execute the command rake db:migrate:
rake aborted!
Don't know how to build task 'db:migrate' (See the list of available tasks with `rake --tasks`)
/usr/local/rvm/gems/ruby-2.5.1/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
(See full trace by running task with --trace)
The result when I execute the command rails --tasks --all:
rails app:template # Applies the template supplied by LOCATION=(/path/t...
rails app:templates:copy #
rails app:update # Update configs and some other initially generated ...
rails app:update:bin #
rails app:update:configs #
rails app:update:upgrade_guide_info #
rails assets:clean[keep] # Remove old compiled assets
rails assets:clobber # Remove compiled assets
rails assets:environment # Load asset compile environment
rails assets:precompile # Compile all the assets named in config.assets.prec...
rails autoprefixer:info # Show selected browsers and prefixed CSS properties...
rails cache_digests:dependencies # Lookup first-level dependencies for TEMPLATE (like...
rails cache_digests:nested_dependencies # Lookup nested dependencies for TEMPLATE (like mess...
rails default #
rails dev:cache # Toggle development mode caching on/off
rails environment #
rails initializers # Print out all defined initializers in the order th...
rails log:clear # Truncates all/specified *.log files in log/ to zer...
rails middleware # Prints out your Rack middleware stack
rails notes # Enumerate all annotations (use notes:optimize, :fi...
rails notes:custom # Enumerate a custom annotation, specify with ANNOTA...
rails notes:fixme #
rails notes:optimize #
rails notes:todo #
rails restart # Restart app by touching tmp/restart.txt
rails routes # Print out all defined routes in match order, with ...
rails secret # Generate a cryptographically secure secret key (th...
rails stats # Report code statistics (KLOCs, etc) from the appli...
rails test # Runs all tests in test folder except system ones
rails test:controllers #
rails test:db # Run tests quickly, but also reset db
rails test:functionals #
rails test:generators #
rails test:helpers #
rails test:integration #
rails test:jobs #
rails test:mailers #
rails test:models #
rails test:prepare #
rails test:run #
rails test:system # Run system tests only
rails test:units #
rails time:zones[country_or_offset] # List all time zones, list by two-letter country co...
rails time:zones:all #
rails time:zones:local #
rails time:zones:us #
rails tmp #
rails tmp/cache #
rails tmp/cache/assets #
rails tmp/pids #
rails tmp/sockets #
rails tmp:cache:clear #
rails tmp:clear # Clear cache, socket and screenshot files from tmp/...
rails tmp:create # Creates tmp directories for cache, sockets, and pids
rails tmp:pids:clear #
rails tmp:screenshots:clear #
rails tmp:sockets:clear #
rails yarn:install # Install all JavaScript dependencies as specified v...
I would be very grateful if you could help me on this problem !
Thank you in advance !
Aurèle
This happens probably due ruby version upgrade.
Try to install the gems again with bundle install and then try again.
If don't work you'll need to run as bundle exec rails db:migrate for bundle pick the right version of the gems.
EDIT: since your are using rvm, make sure you're using the same Ruby versions. Take a look at this https://rvm.io/workflow/projects and make sure you're in the right version.
Hint: Check the Ruby version in the Gemfile, as it could be the source of your problem.
I'm following Ruby on Rails Tutorial (Rails 5) Learn Web Development with Rails
Michael Hartl, using rails 5.0.0.1, when I tried to run the following command in bash
rails generate scaffold User name:string email:string
I received this error
Version: 1.7.2
Usage: spring COMMAND [ARGS]
Commands for spring itself:
binstub Generate spring based binstubs. Use --all to generate a binstub for all known commands. Use --remove to revert.
help Print available commands.
server Explicitly start a Spring server in the foreground
status Show current status.
stop Stop all spring processes for this project.
Commands for your application:
rails Run a rails command. The following sub commands will use spring: console, runner, generate, destroy, test.
rake Runs the rake command
rails aborted!
Don't know how to build task 'rails' (see --tasks)
/home/Medo/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/rake_proxy.rb:13:in `block in run_rake_task'
/home/Medo/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/rake_proxy.rb:10:in `run_rake_task'
/home/Medo/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
/home/Medo/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:9:in `require'
bin/rails:9:in `<main>'
(See full trace by running task with --trace)
I don't know what causing this issue and can't see a solution for it after hour of searching.
Well this what worked for me
bundle install --binstubs
after it, rails worked without a problem
This is what help give us. I just run this 3 commands and it's work.
Looks like your app's ./bin/rails is a stub that was generated by
Bundler.
In Rails 5, your app's bin/ directory contains executables that are
versioned like any other source code, rather than stubs that are
generated on demand.
Here's how to upgrade:
bundle config --delete bin # Turn off Bundler's stub generator
rails app:update:bin # Use the new Rails 5 executables
git add bin # Add bin/ to source control
You may need to remove bin/ from your .gitignore as well.
I am not sure but maybe it can help
$ spring stop
$ rails generate scaffold User name:string email:string
Can you check if rails s is working.Also try
bin/rails generate scaffold User name:string email:string
UserMailer with delay method not working in rails 4. As mentioned below, this code doesn't works
def welcome_email
UserMailer.delay.welcome_email(self)
end
But when I use below code it works fine.
UserMailer.welcome_email(self).deliver
I have installed 2 gems, i.e
gem 'delayed_job'
gem 'delayed_job_active_record'
You need to pass ENV variables to your worker command.
Use this command in your command line:
rake jobs:work RAILS_ENV=development VARIABLE_1='' VARIABLE_2=''
I'm building a Rails Engine inside another rails app. The engine's rake tasks seem to get scoped to app:
# inside <app_root>/engines/engine_name
$ rake -T apartment
rake app:apartment:migrate # Migrate all tenants
Whereas from the app's root:
#inside <app_root>/
$ rake -T apartment
rake apartment:migrate # Migrate all tenants
My problem is when I run
# inside <app_root>/engines/engine_name
RAILS_ENV=test rake db:migrate
I get the following error:
rake aborted! Don't know how to build task 'apartment:migrate'
Seems like it should be calling the app:apartment:migrate task, but I'm not sure how to do this so I can test this engine on its own with RSpec
You should have a Rakefile for the engine here: <app_root>/engines/engine_name/Rakefile
Try adding this line to the bottom of it to load the rake tasks from the apartment gem:
load 'tasks/apartment.rake'
I am developing rails 2.3.2 application.
When I type the command "rails script/server"
I got the following output instead of server starting why?
rails script/server
Usage:
rails new APP_PATH [options]
Options:
-J, [--skip-javascript] # Skip JavaScript files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge] # Setup the application with Gemfile pointing to Rails repository
-G, [--skip-git] # Skip Git ignores and keeps
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
-b, [--builder=BUILDER] # Path to a application builder (can be a filesystem path or URL)
[--old-style-hash] # Force using old style hash (:foo => 'bar') on Ruby >= 1.9
[--skip-gemfile] # Don't create a Gemfile
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
-O, [--skip-active-record] # Skip Active Record files
[--skip-bundle] # Don't run bundle install
-T, [--skip-test-unit] # Skip Test::Unit files
-S, [--skip-sprockets] # Skip Sprockets files
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /home/xichen/.rvm/rubies/ruby-1.8.7-p352/bin/ruby
-j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library
# Default: jquery
Runtime options:
-q, [--quiet] # Supress status output
-s, [--skip] # Skip files that already exist
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
Rails options:
-h, [--help] # Show this help message and quit
-v, [--version] # Show Rails version number and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.
When I type linux command "ls" I got the following directories and files showing:
app Capfile config criptq db doc features Gemfile Gemfile.lock generate lib log nbproject public Rakefile README script spec test tmp vendor
my Gemfile is:
source "http://rubygems.org"
gem "rails", "2.3.2"
gem "mysql", "2.8.1"
gem "fastercsv"
gem "will_paginate", "2.3.16"
gem "chronic", "0.6.4"
gem "whenever", "0.4.1"
gem "searchlogic", "2.4.28"
group :development do
gem "mongrel", "1.1.5"
end
group :test do
gem "rspec", "1.3.2"
gem "rspec-rails", "1.3.4"
gem "factory_girl", "1.3.3"
end
In a Rails 2.3 app it is just ./script/server start
For rails 3.2.3 and latest version of rails you can start server by:
First install all gem with command: bundle install or bundle.
Then Configure your database to the database.yml.
Create new database: rake db:create
Then start rails server.
rails server orrails s
For rails 2.3.2 you can start server by:
ruby script/server
In rails 2.3.x application you can start your server by following command:
ruby script/server
In rails 3.x, you need to go for:
rails s
Make sure you're in the right directory when you start the server
sites>yoursite> rails s
On rails 3, the simpliest way is rails s.
In rails 2, you can use ./script/server start.
You can also use another servers, like thin or unicorn, that also provide more performance.
I use unicorn, you can easily start it with unicorn_rails.
BTW, if you use another things, like a worker (sidekiq, resque, etc), I strongly recommend you to use foreman, so you can start all your jobs in one terminal windows with one command and get a unified log.
For rails 4.1.4 you can start server:
$ bin/rails server
Goto root directory of your rails project
In rails 2.x run > ruby script/server
In rails 3.x use > rails s
For newest Rails versions
If you have trouble with rails s, sometimes terminal fails.
And you should try to use:
./bin/rails
To access command.
For the latest version of Rails (Rails 5.1.4 released September 7, 2017), you need to start Rails server like below:
hello_world_rails_project$ ./bin/rails server
=> Booting Puma
=> Rails 5.1.4 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.10.0 (ruby 2.4.2-p198), codename: Russell's Teapot
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
More help information:
hello_world_rails_project$ ./bin/rails --help
The most common rails commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
server Start the Rails server (short-cut alias: "s")
test Run tests except system tests (short-cut alias: "t")
test:system Run system tests
dbconsole Start a console for the database specified in
config/database.yml
(short-cut alias: "db")
new Create a new Rails application. "rails new my_app" creates a
new application called MyApp in "./my_app"
If you are in rails2 version then to start the server you have do,
script/server or
./script/server
But if you are in rails3 or above version then to start the server you have do,
rails server or
rails s
in rails 2.3.X,just type following command to start rails server on linux
script/server
and for more help read "README" file which is already created in rails project folder
I also faced the same issue, but my fault was that I was running "rails s" outside of my application directory.
After opening the cmd, just go inside your application and run the commands from their, it worked for me.
You have to cd to your master directory and then rails s command will work without problems.
But do not forget bundle-install command when you didn't do it before.
run with nohup to run process in the background permanently if ssh shell is closed/logged out
nohup ./script/server start > afile.out 2> afile.err < /dev/null &
Rails version < 2
From project root run:
./script/server
I believe this is what happens if "rails new [project]" has not actually executed correctly. If you are doing this on windows and "rails server" just returns the help screen, you may need to restart your command prompt window and likely repeat your setup instructions. This is more likely true if this is your first time setting up the environment.