Gem Dependencies on Rails Engines

I followed Getting Started with Engines in the Rails documentation and I set up the engine api

in a directory engines

. As per paragraph 6.6 Other Gem Dependencies, it is supposed to define the gem dependencies in the file engines/my_api/my_api.gemspec

, and this is pretty much what I did:

s.add_dependency "responders", "2.0"

      

After adding

`gem 'my_api', path: "engines/my_api"`

      

for apps Gemfile

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 engines/my_api/app/controllers/my_api/application_controller.rb

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 Gemfile

, launched it bundle install

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 Gemfile

?

EDIT:

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)

      

+3


source to share


1 answer


As you noticed, a gem is included in your kit, whether it's in your Gemfile application or not. The difference is that when Bundler.require

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

+1


source







All Articles