I have a mountable engine called Blog
that apps can use.
What's the best way to allow apps that use the engine to set a configuration variable like site_name
(so that the engine can display it in the design)?
Update:
I've seen some gems create a 'config/initializers/gem_name.rb' file. Is there any specification on how to:
I tried creating Blog.site_name = "My Site"
in the app's config/initializers/blog.rb
file but get an Undefined method error.
Figured out an even better solution that also allows you to set default values (incase the app using the engine doesn't specify a config)...
/config/initializers/blog.rb
like this: Blog.setup do |config|
config.site_name = "My Site Name"
end
/lib/blog/engine.rb
set default values like this: module Blog
self.mattr_accessor :site_name
self.site_name = "Site Name"
# add default values of more config vars here
# this function maps the vars from your app into your engine
def self.setup(&block)
yield self
end
end
Blog.site_name
Much cleaner.