plugins aren't perfect either September 26th, 2007
In an attempt to wrangle the AssetPackager plugin into the Yellowpages site today, I came across this snippet.
sources = (RAILS_ENV == "production" ?
AssetPackage.targets_from_sources("stylesheets", sources) :
AssetPackage.sources_from_targets("stylesheets", sources))
RAILS_ENV == "production"? Because nobody has a staging or QA environment that should mimic the behavior of a production environment. Right?
The plugin has a lot of good things going for it. It was easy to configure and implement, but this is a pain in the ass.
My fix....
sources = (use_packaged_assets? ?
AssetPackage.targets_from_sources("stylesheets", sources) :
AssetPackage.sources_from_targets("stylesheets", sources))
....
def use_packaged_assets?
RAILS_ENV == "production" || USE_PACKAGED_ASSETS == true
end
Which allows me to add the USE_PACKAGED_ASSETS constant into various environments to toggle this feature on for testing purposes.
Does anybody have a better way to implement integration with various environments? I'm open to suggestion.
EDIT! Blogging my very own shame! Former Boss Steve noticed that I'd error out if the constant wasn't defined.
def use_packaged_assets?
RAILS_ENV == "production" || (defined? USE_PACKAGED_ASSETS && USE_PACKAGED_ASSETS == true)
end