Closed deepakmahakale closed 3 years ago
Hi @deepakmahakale 👋🏻
Are you able to reproduce it in new Rails app? If so, would you mind send a sample repo so we can take a look at?
Thanks 🙌🏻
Sure, I will try the same in the new rails app and share the repo here.
Thanks for the quick response.
@feliperenan
It is working in a new rails app. But not in my main application.
I went back and tried manually requiring simple_form
in the initializers and it is working.
Not sure if it's because of some config, autoloader setting, or something else.
# config/initializers/simple_form.rb
require 'simple_form'
SimpleForm.setup do |config|
# ....
# ....
end
/Users/deepak/workspace/my_project/config/initializers/simple_form.rb:11:in `<main>': undefined method `setup' for SimpleForm:Module (NoMethodError)
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:326:in `block in load'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:299:in `load_dependency'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:326:in `load'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/engine.rb:681:in `block in load_config_initializer'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/activesupport-6.1.3.2/lib/active_support/notifications.rb:205:in `instrument'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/engine.rb:680:in `load_config_initializer'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/engine.rb:634:in `block (2 levels) in <class:Engine>'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/engine.rb:633:in `each'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/engine.rb:633:in `block in <class:Engine>'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/initializable.rb:32:in `instance_exec'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/initializable.rb:32:in `run'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/initializable.rb:61:in `block in run_initializers'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:228:in `block in tsort_each'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/initializable.rb:50:in `each'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/initializable.rb:50:in `tsort_each_child'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:415:in `call'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:415:in `each_strongly_connected_component_from'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:347:in `each'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:347:in `call'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:347:in `each_strongly_connected_component'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:226:in `tsort_each'
from /Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/tsort.rb:205:in `tsort_each'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/initializable.rb:60:in `run_initializers'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/railties-6.1.3.2/lib/rails/application.rb:384:in `initialize!'
from /Users/deepak/workspace/my_project/config/environment.rb:7:in `<main>'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:332:in `block in require'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:299:in `load_dependency'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/activesupport-6.1.3.2/lib/active_support/dependencies.rb:332:in `require'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/spring-2.1.1/lib/spring/application.rb:106:in `preload'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
from /Users/deepak/.rvm/gems/ruby-3.0.0@my_project/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
from <internal:/Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/Users/deepak/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from -e:1:in `<main>'
and this is environment.rb
line 7 is Rails.application.initialize!
# frozen_string_literal: true
# Load the Rails application.
require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
How is simple form listed in your Gemfile? And how is Bundler requiring things in your config/application? Bundler should be requiring all gems on the current environment correctly including simple form, unless you're explicitly saying "require: false".
My bad!!
In a hurry, I had added it in the development
block.
I spent almost an hour figuring out the issue.
Thanks for the support @carlosantoniodasilva @feliperenan
undefined method `setup' for SimpleForm:Module (NoMethodError)
Environment
Current behavior
Works with
rails s
but when I try to runrails test
I get the following errorExpected behavior
Should be able to run
rails test