我目前正在构建一个Rails引擎,并且在我的gemspec文件中,我有这样添加的宝石meta-tags
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 = ["techgroup@finology.com.my"]
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
并且我还添加了一个文件,将这个gem的初始化程序配置复制到这样的主应用程序中
在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
在我的main_application中,运行rails g insurance:install
时会像这样创建config / initializers / meta_tags.rb文件
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
但是当我运行rails时,出现错误config/initializers/meta_tags.rb:2:in
':未初始化的常量MetaTags(NameError)`。
那么我应该如何在我的rails引擎中添加一个gem并能够从我的rails引擎或我的主应用程序中调用常量。
任何建议都值得赞赏