Don't know how to build task 'rails'

11,830

Solution 1

Well this what worked for me

bundle install --binstubs

after it, rails worked without a problem

Solution 2

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.

Solution 3

I am not sure but maybe it can help

$ spring stop
$ rails generate scaffold User name:string email:string
Share:
11,830

Related videos on Youtube

Medo
Author by

Medo

Updated on September 14, 2022

Comments

  • Medo
    Medo over 1 year

    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.

  • Medo
    Medo over 7 years
    I get spring is not running when I type spring stop and when I try rails generate I get the same error message
  • Aleksey
    Aleksey over 7 years
    Have you tried bundle exec rails generate ... or bin/rails generate if you have binstub?
  • Medo
    Medo over 7 years
    yes same thing, always says Don't know how to build task 'rails'
  • Moondustt
    Moondustt about 7 years
    This solved the rails g and rails c problem for me, nice!
  • lucyjosef
    lucyjosef over 2 years
    spring seems to cause rails command issues on macos, I'm used to spring stop once a month, it works much better then