Rails webpacker:install fails with generic error - ruby-on-rails

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

Related

I want to migrate paperclip gem to active_storage Ruby on Rails 7

...like this: paperclip2active_storage
Update be sure to watch the linked video presentation as the text document does not present all the quirks!
so I installed and configured rails 7 and gem 'mini_magick'. Now I suppose the referenced script will update all my models, views and controllers:
but, when I run it I get error like this:
leder#home-ryzen-desktop:~/Git/gmr_production_heroku$ ruby migration.rb
migration.rb:1:in `<main>': uninitialized constant ActiveRecord (NameError)
migration.rb as described in the referenced link!
How do I do migrate my RoR App?
I have removed development from database.yml and added to storage.yml:
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
amazon:
...
Now I get this error:
leder#home-ryzen-desktop:~/Git/gmr_production_heroku$ bundle exec rake db:create
rake aborted!
ActiveRecord::AdapterNotSpecified: The `development` database is not configured for the `development` environment.
Available database configurations are:
production
/home/leder/.rbenv/versions/3.0.1/bin/bundle:23:in `load'
/home/leder/.rbenv/versions/3.0.1/bin/bundle:23:in `<main>'
Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)
How do I migrate this to active_storage?
Follow up question can be found here: Part2
You need to run the migration in the context of Rails. So ruby migration.rb won't work.
You need to generate a migration with bin/rails g migration <migration_name>.
Then once you copy the code into the migration, run bin/rails db:migrate.
P.S. Rails 7 hasn't been released yet. So moving to Rails 7 might be premature since it may still have bugs and many gems may not support it fully

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.

Rails 5.2 with master.key Digital Ocean deployment: ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage

I have migrated my Ruby on Rails application from Rails 5.1.2 to Rails 5.2.0 to use the encrypted secrets. Application is successfully deployed to Digital Ocean Ubuntu Server. But when I go in browser to access, it shows the following log.
ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt'
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:184:in `_decrypt'
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_file.rb:79:in `decrypt'
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_file.rb:42:in `read'
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:21:in `read'
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:33:in `config'
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:38:in `options'
/home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
(erb):12:in `<main>'
I have added encrypted secrets using rails credentials:edit, which creates config/credentials.yml.enc and master.key.
I also have added the master.key file on /app_name/shared/config/ on my ubuntu server, also placed an env variable RAILS_MASTER_KEY. But still getting this error, I don't know what I am missing here.
Solution A and B are different solutions. Just choose which is good for you.
a. Deploy from Continous Integration
1. Edit deploy.rb
set :default_env, {
"RAILS_ENV" => "production",
"RAILS_MASTER_KEY" => ENV["RAILS_MASTER_KEY"]
}
2. Add RAILS_MASTER_KEY as a variable
Travis CI
GitLab CI
b. Usage of master.key
1. Edit deploy.rb
append :linked_files, "config/master.key"
2. Upload master.key with :linked_files
Let's assume our application's root path is /home/deploy/awesome-project. All we need to do is upload the key file to /home/deploy/awesome-project/shared/config/master.key.
I faced the same problem, when deploying for the first time on my DigitalOcean Droplet, every time I ran RAILS_ENV=production cap production deploy:initial it failed complaining this error - ActiveSupport::MessageEncryptor::InvalidMessage
I tried below options which all failed -
removing master.key and credential.yml.enc file and then deploying again.
adding both files again and deploying.
Finally one solution worked, i just added master.key, removing credentials.yml.enc file, committed it and redeployed, and it worked without changing my deploy.rb file

What's a Capfile? And how do I use it correctly with Ruby on Rails?

I have a ruby on rails application that should be transferred from one server to another (that's not working fine at the moment). I installed capistrano. I'm using debian 7 server with apache passenger.
I saw a Capfile in the root directory of the ruby on rails application.
Is a Capfile something like a makefile to build and deploy the application? How do I correctly work with it?
UPDATE
When I run the cap file i got this: ' cap deploy:setup '
(Backtrace restricted to imported tasks)
cap aborted!
LoadError: cannot load such file -- config/deploy
/var/www/myapplication/Capfile:3:in `load'
/var/www/myapplication/Capfile:3:in `<top (required)>'
(See full trace by running task with --trace)
it seems like the deploy file coun't be loaded ... i have in the config folder an deploy folder and a deploy.rb
whats going wrong?
This is happening because Capistrano tasks are now Rake tasks and Rake expects a construct like this:
task :name, [:arg, :arg] => :dependency do
...
end
Capistrano 3:
task :dump do
on primary roles :db do
...
end
end

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.

Resources