cannot seem to update the rails executable in bin/ - ruby-on-rails

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.

Related

Rails webpacker:install fails with generic error

I am new to Ruby on Rails and this is the very first project I have attempted. I installed Rails and got to the screen that lets me know that I have successfully installed Rails. Rails Page
I ran rails g controller home index to create my first web page. It completed successfully and displayed this:
user#Ubuntu:~/dev/app$ rails g controller home index
Running via Spring preloader in process 183578
create app/controllers/home_controller.rb
route get 'home/index'
invoke erb
create app/views/home
create app/views/home/index.html.erb
invoke test_unit
create test/controllers/home_controller_test.rb
invoke helper
create app/helpers/home_helper.rb
invoke test_unit
invoke assets
invoke scss
create app/assets/stylesheets/home.scss
I tried to access the page, but it gave me this error:
Webpacker can't find application.js in /home/user/dev/app/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
I tried changing cache_manifest: false and extract_css: false in webpacker.yml to true but it didn't seem to help. I felt that webpacker was not installed correctly so I ran rails webpacker:install. It fails and never successfully completes:
`user#Ubuntu:~/dev/app$ bundle exec rails webpacker:install
conflict config/webpacker.yml
Overwrite /home/user/dev/app/config/webpacker.yml? (enter "h" for help) [Ynaqdhm] n
skip config/webpacker.yml
Copying webpack core config
exist config/webpack
identical config/webpack/development.js
identical config/webpack/environment.js
identical config/webpack/production.js
identical config/webpack/test.js
Copying postcss.config.js to app root directory
identical postcss.config.js
Copying babel.config.js to app root directory
identical babel.config.js
Copying .browserslistrc to app root directory
identical .browserslistrc
rails aborted!
NoMethodError: undefined method `exists?' for Dir:Class
/home/user/dev/app/bin/rails:5:in `<top (required)>'
/home/user/dev/app/bin/spring:10:in `require'
/home/user/dev/app/bin/spring:10:in `block in <top (required)>'
/home/user/dev/app/bin/spring:7:in `<top (required)>'
Tasks: TOP => app:template`
Any idea how to resolve this? This error is so generic, I am having trouble searching for answers.
rails aborted!
NoMethodError: undefined method `exists?' for Dir:Class
Environment:
Ubuntu 22.04 LTS Desktop |
Rails version: 6.1.7 |
Ruby version: 3.2.0

Can not execute commands like "rails db:*"

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.

Don't know how to build task '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

Migrating database fails after upgrading to Ruby 2.3.0

I've updated to Ruby 2.3.0 and I'm having some issues when creating a new Rails app. After creating a simple new test app and scaffolding a resource, when trying to execute rake db:migrate I'm getting the following load error:
MacBook-Pro:log medright1$ rake db:migrate
/Users/medright1/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rake-10.4.2/bin/rake:31:in `require': cannot load such file -- rake (LoadError)
from /Users/medright1/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rake-10.4.2/bin/rake:31:in `<top (required)>'
from /Users/medright1/.rvm/gems/ruby-2.3.0/bin/rake:23:in `load'
from /Users/medright1/.rvm/gems/ruby-2.3.0/bin/rake:23:in `<main>'
from /Users/medright1/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/medright1/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
MacBook-Pro:log medright1$
Any help sorting this would be great!
If you haven't done it yet, make sure you have all the dependencies installed.
$ bundle
or
$ bundle install
It's likely you don't have rake installed in the global RVM gemset. In any case, given you are within a Rails project, you should use bundler to execute the command.
$ bundle exec rake db:migrate
Otherwise, make sure to install rake globally
$ rvm gemset use global
$ gem install rake
However, the correct way is to execute the command via Bundler.

Why I am not able to run rails tests

This is what I did.
> git clone git://github.com/rails/rails.git
> cd rails
> cd railties
> rake
And I got following error.
(in /Users/dorelal/dev/scratch/rails/railties)
./test/isolation/abstract_unit.rb:236:in `initialize': No such file or directory - /Users/dorelal/dev/scratch/rails/railties/tmp/app_template/config/boot.rb (Errno::ENOENT)
from ./test/isolation/abstract_unit.rb:236:in `open'
from ./test/isolation/abstract_unit.rb:236
from ./test/isolation/abstract_unit.rb:222:in `initialize'
from ./test/isolation/abstract_unit.rb:222:in `new'
from ./test/isolation/abstract_unit.rb:222
from test/application/configuration_test.rb:1:in `require'
from test/application/configuration_test.rb:1
rake aborted!
I checked ~/railties/tmp and this directory is empty.
I know rails is not broken. So what am I missing?
You need to run bundle install after you cd rails. That will install all the gems required by your new Rails repo, including minitest (test-unit at the time of your question.)
After you run bundle install, you will be able to run the rails tests by doing a cd into the component directory and then either running the entire test suite for that component, or specifying a single test file, as follows (using actionpack as an example):
To run all tests for actionpack:
cd actionpack
TEST_DIR=generators bundle exec rake test
To run the tests for actionpack test/dispatch/rack_test.rb:
cd actionpack
bundle exec ruby -Itest test/dispatch/rack_test.rb
To run the entire test suite for all of rails:
cd rails
bundle exec rake test
A Necromancer cannot resist such a question - so old, yet so relevant, so cleanly asked, so not documented properly.

Resources