So, I’m not having a problem so much as I am confused by two different conventions that I see used around the web for changing the Rails config files.
Specifically, I see these two statements used often:
config.autoload_paths << "#{Rails.root}/app/arbitrary"
config.autoload_paths += %W(#{config.root}/app/arbitrary)
config.autoload_paths += Dir["#{config.root}/app/arbitrary/**/"]
First, is there any difference n using the << operator vs the += operator?
Second, is it considered a better practice to use Rails.root as opposed to config.root?
Can some of these conventions only be used in certain combinations? I just hate not knowing something so seemingly basic.
difference between
<<and+=config.autoload_pathsis an Array. For an Array object,<<push ONE object to the array, while+joins two array to create a new array. So if you only have one object to be appended to the existing array,<<is preferred for performance because no new object will be created. If you want to append another array to the existing array, you have to use+.Yo know,
a1 =+ a2is equal toa1 = a1 + a2.Rails.rootv.s.config.rootRails.rootis just the root of Rails app.If
config.rootis used in a Rails app, it should be same asRails.root. But it can also be used in Engines, where it will be the Engine’s root. Ifconfig.rootis used in a Rails app, you may not have to change it to use the app as an Engine.