Gem Dependencies on Rails Engines
I followed Getting Started with Engines in the Rails documentation and I set up the engine
in a directory
. As per paragraph 6.6 Other Gem Dependencies, it is supposed to define the gem dependencies in the file
, and this is pretty much what I did:
s.add_dependency "responders", "2.0"
`gem 'my_api', path: "engines/my_api"`
and running package, everything looks as expected:
bundle install | grep responders Installing responders 2.0.0
In the next step, I set the root path with the appropriate controller, etc. and go to
and add the following content:
module MyApi class ApplicationController < ActionController::Base respond_to :json end end
I started the rails server, started up the root url and guess what? I receive the following message:
The response_to function at the controller level has been retrieved into responders' memory. Add it to your Gemfile to continue using this feature: gem "responseers", "~> 2.0" See the Rails Upgrade Guide for details.
As suggested in the error message, I added the gem to the apps
, launched it
and everything worked as expected.
As far as I understood, the engines should be standalone rails applications. From a standalone application, I would at least expect a correct solution to my dependencies. I am guessing that I am just doing something wrong and I am hoping someone can help me solve the problem, why should I explicitly list the gem in applications
Forgot to mention the versions:
$ gem list | grep rails coffee-rails (4.1.0) jquery-rails (4.0.3) rails (4.2.1) rails-deprecated_sanitizer (1.0.3) rails-dom-testing (1.0.6) rails-html-sanitizer (1.0.2) sass-rails (5.0.3) sprockets-rails (2.2.4)
source to share
As you noticed, a gem is included in your kit, whether it's in your Gemfile application or not. The difference is that when
called during application initialization, it only automatically requires a Gemfile in your application, not an indirect dependency.
If your gem requires a respondent gemstone to be loaded, it must require it explicitly - for example, at the top of my_api.rb
source to share