1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

add note about requiring gem dependencies before initialization [ci skip]

This commit is contained in:
Francesco Rodriguez 2012-07-12 13:39:26 -05:00
parent 8ee3651bd2
commit bc65d0c581

View file

@ -563,7 +563,7 @@ end
By default, the engine's controllers inherit from <tt>Blorgh::ApplicationController</tt>. So, after making this change they will have access to the main applications +ApplicationController+ as though they were part of the main application.
This change does require that the engine is run from a Rails application that has an +ApplicationController+.
This change does require that the engine is run from a Rails application that has an +ApplicationController+.
h4. Configuring an engine
@ -741,7 +741,7 @@ h4. Separate Assets & Precompiling
There are some situations where your engine's assets not required by the host application. For example, say that you've created
an admin functionality that only exists for your engine. In this case, the host application doesn't need to require +admin.css+
or +admin.js+. Only the gem's admin layout needs these assets. It doesn't make sense for the host app to include +"blorg/admin.css"+ in it's stylesheets. In this situation, you should explicitly define these assets for precompilation.
This tells sprockets to add you engine assets when +rake assets:precompile+ is ran.
This tells sprockets to add you engine assets when +rake assets:precompile+ is ran.
You can define assets for precompilation in +engine.rb+
@ -755,18 +755,40 @@ For more information, read the "Asset Pipeline guide":http://guides.rubyonrails.
h4. Other gem dependencies
Gem dependencies inside an engine should be specified inside the +.gemspec+ file that's at the root of the engine. The reason for this is because the engine may be installed as a gem. If dependencies were to be specified inside the +Gemfile+, these would not be recognised by a traditional gem install and so they would not be installed, causing the engine to malfunction.
Gem dependencies inside an engine should be specified inside the +.gemspec+ file
that's at the root of the engine. The reason for this is because the engine may
be installed as a gem. If dependencies were to be specified inside the +Gemfile+,
these would not be recognised by a traditional gem install and so they would not
be installed, causing the engine to malfunction.
To specify a dependency that should be installed with the engine during a traditional +gem install+, specify it inside the +Gem::Specification+ block inside the +.gemspec+ file in the engine:
To specify a dependency that should be installed with the engine during a
traditional +gem install+, specify it inside the +Gem::Specification+ block
inside the +.gemspec+ file in the engine:
<ruby>
s.add_dependency "moo"
</ruby>
To specify a dependency that should only be installed as a development dependency of the application, specify it like this:
To specify a dependency that should only be installed as a development
dependency of the application, specify it like this:
<ruby>
s.add_development_dependency "moo"
</ruby>
Both kinds of dependencies will be installed when +bundle install+ is run inside the application. The development dependencies for the gem will only be used when the tests for the engine are running.
Both kinds of dependencies will be installed when +bundle install+ is run inside
the application. The development dependencies for the gem will only be used when
the tests for the engine are running.
Note that if you want to immediately require dependencies when the engine is
required, you should require them before engine's initialization. For example:
<ruby>
require 'other_engine/engine'
require 'yet_another_engine/engine'
module MyEngine
class Engine < ::Rails::Engine
end
end
</ruby>