Don't know how to build task 'rails' - ruby-on-rails

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

Related

accessing Rails Console after deploy to server

I´m having trouble to access the rails console in production.
I used Capistranoto deploy the app to a VPS
If I cd to deploy#myapp:~/myapp/current$and run bundle exec rails cthere I always get the option list for creating new rails project, like rails new
I've also tried bundle exec rails console --productionand rails consoleetc all with the same outcome.
the thing is I must be able to access the console because I have to create an admin user for active admin
might be worth adding that I'm using Passenger/Capistrano and Nginx on Ubuntu 16
Does anyone know what is going on here? Am I doing something wrong?
*EDIT
After running RAILS_ENV=production bundle exec rails c I get this message
Looks like your app's ./bin/rails is a stub that was generated by Bundler.
In Rails 4, 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
rake rails:update:bin # Use the new Rails 4 executables
git add bin # Add bin/ to source control
You may need to remove bin/ from your .gitignore as well.
When you install a gem whose executable you want to use in your app,
generate it and add it to source control:
bundle binstubs some-gem-name
git add bin/new-executable
Loading production environment (Rails 4.2.5)
irb(main):001:0>
You are missing executable files of bin folder in Production after Capistrano deployment.
You need to remove bin from set :linked_dirs from your Capistrano deploy.rb in order to avoid symlinking it.
You can again try cap production deploy, it would take all the executable files from bin to Production.
Now, you can access the rails console using:
RAILS_ENV=production bundle exec rails c
If you are using Capistrano 3, you can include the rails:console option which will allow you to do this from your local machine to gain access to the console on the remote host:
bundle exec cap production rails:console
https://rubygems.org/gems/capistrano-rails-console
The Rails project is deployed in /deploy/your_project_name/current on the server by default. So, you can access it via SSH or ... and run bundle exec rails c to access the Rails console. It works for me!
check if rvm and regarding gemset is suitable for the app
rvm gemset list
rvm list
and then do
bin/rails rails c -e production

Command: rails console, generate not recognize. Error: Command 'rails' not recognized Usage: rails COMMAND [ARGS]

When I go to rails folder (I'm inside my rails app folder) and type "rails c" or "rails g" it said:
Error: Command 'rails' not recognized
Usage: rails COMMAND [ARGS]
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
Error: Command 'rails' not recognized
Usage: rails COMMAND [ARGS]
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")
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"
In addition to those, there are:
destroy Undo code generated with "generate" (short-cut alias: "d")
plugin new Generates skeleton for developing a Rails plugin
runner Run a piece of code in the application environment (short-cut alias: "r")
All commands can be run with -h (or --help) for more information.
I'm running Linux Subsystem for Windows 10, I know I know you see Windows but it's kind of... Linux, and I installed Ruby by rbenv through this tutorial.
Try this command from your app folder:
rake rails:update:bin
Say y to replace the binaries.
I had the same problem using rails with Windows Linux Subsystem. I found the suggestion here:
Rails command Error
I tried it and it solved my problem, so maybe yours as well.
Even though the accepted answer solved your issue, I want to add another because I ran into the same error message but the underlying issue and my environment setup wasn't the same. However, recreating the executables in my app's bin folder did not solve the problem.
The issue: When I tried running bundle exec rails s or bundle exec rails c I got the same error as posted in the question. Using the apps executables worked fine though ./bin/rails s.
So the main differences from the question: I was using bundle exec when I got the error.
What was happening behind the scenes: bundle exec rails s was calling this executable /Users/robin/.rvm/gems/ruby-2.3.8/bin/rails which is shipped by the railties gem. I found this file was overwritten due to a gem which had an executable rails defined in its .gemspec.
What solved my problem:
Running $ bundle pristine railties (https://bundler.io/v2.0/man/bundle-pristine.1.html) so railties would be reset and with that the executable shipped by railties would overwrite the wrong one.
Addition: Of course it only helps as long as the intrusive gem shipping a rails executable is also updated and no longer wants it to be installed.

cannot seem to update the rails executable in bin/

I have a rails project where I use bin/rails instead of just calling rails its self. upon upgrading to rails 4.2, I did:
rm -rf .bundle/gems
bundle
When everything finished, I did bin/rails
$ bin/rails
Looks like your app's ./bin/rails is a stub that was generated by Bundler.
In Rails 4, 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
rake rails:update:bin # Use the new Rails 4 executables
git add bin # Add bin/ to source control
You may need to remove bin/ from your .gitignore as well.
When you install a gem whose executable you want to use in your app,
generate it and add it to source control:
bundle binstubs some-gem-name
git add bin/new-executable
/Users/Adam/Documents/Rails-Projects/Libraries-and-Helpers/Xaaron/.bundle/gems/gems/railties-4.2.0/lib/rails/app_rails_loader.rb:44:in `require': cannot load such file -- /Users/Adam/Documents/Rails-Projects/Libraries-and-Helpers/Xaaron/config/boot (LoadError)
from /Users/Adam/Documents/Rails-Projects/Libraries-and-Helpers/Xaaron/.bundle/gems/gems/railties-4.2.0/lib/rails/app_rails_loader.rb:44:in `block in exec_app_rails'
from /Users/Adam/Documents/Rails-Projects/Libraries-and-Helpers/Xaaron/.bundle/gems/gems/railties-4.2.0/lib/rails/app_rails_loader.rb:34:in `loop'
from /Users/Adam/Documents/Rails-Projects/Libraries-and-Helpers/Xaaron/.bundle/gems/gems/railties-4.2.0/lib/rails/app_rails_loader.rb:34:in `exec_app_rails'
from /Users/Adam/Documents/Rails-Projects/Libraries-and-Helpers/Xaaron/.bundle/gems/gems/railties-4.2.0/lib/rails/cli.rb:5:in `<top (required)>'
from /Users/Adam/Documents/Rails-Projects/Libraries-and-Helpers/Xaaron/.bundle/gems/gems/railties-4.2.0/bin/rails:9:in `require'
from /Users/Adam/Documents/Rails-Projects/Libraries-and-Helpers/Xaaron/.bundle/gems/gems/railties-4.2.0/bin/rails:9:in `<top (required)>'
from bin/rails:16:in `load'
from bin/rails:16:in `<main>'
So I assumed I could do, after doing bundle config --delete bin:
rake rails:update:bin
But then I am given:
rake aborted!
Don't know how to build task 'rails'
I am running this from the root of a rails engine that I have created. I am curious as to whats going on. Should I run this command from the dummy app? I suspect not as the bin/ directory is at the root of the engine directory and not the dummy app.
The correct answer based off the comment to the question is to run:
rake app:rails:update:bin
at the root of the engine.

How to run a custom command when run the 'rails server' command?

I am using Ruby on Rails 3.1.0 and the DelayedJob gem. In order to automate processes in development mode I would like to "auto"-run the following command
rake jobs:work
when in my console\terminal I run this other command
rails server
# and/or
#
# rails db:create
# rails db:migrate
# ...
Is it possible? How can I do that?
The gem "foreman" will sort this out for you. Here's the railscast: http://railscasts.com/episodes/281-foreman

Problem with Rake while attempting to install Diaspora on Dreamhost

I am attempting to install a Diaspora pod on my Dreamhost account, following the instructions here:
https://github.com/diaspora/diaspora/wiki/Installing-and-Running-Diaspora
Everything went smooth until it was time to use Rake in order to set up the database. I created the databases using dreamhost's web interface, and then attempted the line given in the guide:
RAILS_ENV=production bundle exec rake db:migrate
The result being:
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake: Is a directory - /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake (Errno::EISDIR)
from /usr/bin/rake:19:in `load'
from /usr/bin/rake:19
It looks like some sort of Rake problem (and indeed, /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake is a directory).
I have some other homemade Ruby-on-Rails projects running on Dreamhost and have no similar problem with rake for them. Their rakefile looks a little different but I'm not sure what causes the problem.
Just a guess, would it help to set RAILS_ENV=production on the end of the line?

Resources