Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails console - undefined method `assets'

On the project the console ceased to be started, I tried everything that found in Google..

I run rails c and get an error:

/Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/railties-5.2.0/lib/rails/railtie/configuration.rb:97:in `method_missing': undefined method `assets' for #<Rails::Application::Configuration:0x007fae6a9bdf78>
Did you mean?  asset_host (NoMethodError)
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/popper_js-1.12.9/lib/popper_js/engine.rb:6:in `block in <class:Engine>'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `instance_exec'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `run'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/railties-5.2.0/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `call'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/railties-5.2.0/lib/rails/initializable.rb:60:in `run_initializers'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/railties-5.2.0/lib/rails/application.rb:361:in `initialize!'
    from /Users/gorbunov/Projects/buktopuha_api/config/environment.rb:5:in `<main>'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /Users/gorbunov/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/gorbunov/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

I don't know what to do. Thanks a lot!

like image 891
Pum Purum Avatar asked Mar 31 '26 01:03

Pum Purum


2 Answers

I had this problem and found the solution here, which was to ensure you have the sprockets line in config/application.rb

require "rails"
 require "active_model/railtie"
 require "active_job/railtie"
 require "active_record/railtie"
 require "active_storage/engine"
 require "action_controller/railtie"
 require "action_mailer/railtie"
 require "action_mailbox/engine"
 require "action_text/engine"
 require "action_view/railtie"
 require "action_cable/engine"
 require "sprockets/railtie"  # <--- make sure this line is here
 require "rails/test_unit/railtie"

Note that the above lines differ a little between rails versions. Find what it should look like for your rails version at the rails guide for your version. Here's rails 6.1, and here's 7.0.


Funnily enough, I had just removed require "sprockets/railtie" since I was trying to remove sprockets. In any case, I put it back in and rails is happy again.

like image 62
stevec Avatar answered Apr 02 '26 15:04

stevec


To add to this answer, you'll also need this in your gemfile

gem 'sprockets-rails'
like image 45
lacostenycoder Avatar answered Apr 02 '26 15:04

lacostenycoder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!