uninitialized constant MetaTags when gem added in rails engine and loaded in another application

409 views Asked by At

I am currently building a rails engine and in my gemspec file i have this gem meta-tags which i have added like this

insurance.gemspec

$:.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "insurance/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |spec|
  spec.name        = "insurance"
  spec.version     = Insurance::VERSION
  spec.authors     = ["Loanstreet Tech"]
  spec.email       = ["[email protected]"]
  spec.homepage    = "https://github.com/loanstreet/insurance_loanstreet_plugin"
  spec.summary     = "Insurance Loanstreet."
  spec.description = "Loanstreet Insurance."
  spec.license     = "MIT"

  spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]

  spec.add_dependency "rails", "~> 5.0.1"

  spec.add_dependency "pg", "0.18"
  spec.add_dependency "meta-tags"

end

and i have also added a file to copy the initializer config of this gem into my main application like this

in lib/generators/insurance/install_generator.rb

module Insurance
  class InstallGenerator < Rails::Generators::Base
    source_root File.expand_path("../../templates", __FILE__)

    def copy_initializer
      template 'meta_tags.rb', 'config/initializers/meta_tags.rb'
    end
  end
end

In my main_application, a config/initializers/meta_tags.rb file is created like this when i run rails g insurance:install

config/initializers/meta_tags.rb

MetaTags.configure do |config|
  # How many characters should the title meta tag have at most. Default is 70.
  # Set to nil or 0 to remove limits.
  config.title_limit = 140

  # When true, site title will be truncated instead of title. Default is false.
  # config.truncate_site_title_first = false

  # Maximum length of the page description. Default is 300.
  # Set to nil or 0 to remove limits.
  config.description_limit = 500

  # Maximum length of the keywords meta tag. Default is 255.
  # config.keywords_limit = 255

  # Default separator for keywords meta tag (used when an Array passed with
  # the list of keywords). Default is ", ".
  # config.keywords_separator = ', '

  # When true, keywords will be converted to lowercase, otherwise they will
  # appear on the page as is. Default is true.
  # config.keywords_lowercase = true

  # When false, generated meta tags will be self-closing (<meta ... />) instead
  # of open (`<meta ...>`). Default is true.
  # config.open_meta_tags = true

  # List of additional meta tags that should use "property" attribute instead
  # of "name" attribute in <meta> tags.
  # config.property_tags.push(
  #   'x-hearthstone:deck',
  # )
end

But when i run rails s, i get error config/initializers/meta_tags.rb:2:in': uninitialized constant MetaTags (NameError)`.

So how else am i supposed to add a gem in my rails engine and be able to call the constant either from my rails engine or from my main application.

Any suggestion is appreciated

0

There are 0 answers