RefineryCMS’ assets somehow use the Rails URL helpers, which causes
rake assets:precompile to throw error, which looks something like this:
1 2 3 4 5
1 2 3 4 5
application.rb which means, on every deployment - compile the assets locally. Which is very inconvinient for any team which does atleast 2-3 QA deploys on an average day !
There is one more alternative given, which suggest use of heroku’s experimental
user_env_compile which means environment will be loaded at the time of compilation. Which seems like an ok idea, but it is an experimental feature, so using that on production can be risky !
Additionally, if you set
config.assets.initialize_on_precompile = true, you end up getting this error on heroku:
1 2 3 4 5 6
But I’m not sure as why this error occured at all. But reagardless, I was not liking the approach to compile assets on every deployments.
The weird solution
Yes, the solution that I finalized was weird and I’m still not onboard with the idea which I’m going to discuss.
I decided to investigate options with not having to compile assets locally on each deploy. If you look at the error it says it cannot find some path which is being acccessed from some erb. I decided to somehow load the refinery engine routes at the compile time. And to do that very shamelessly I begged Google for help, and as most of the times Stack Overflow came to rescue :-)
The first answer to this question was basically something that enlightened me.
Here is the snippet from the answer:
1 2 3 4 5 6 7 8
As the question was about loading SOME initializer while compiling assets, this code just loads the load_config.rb.
We on the other hand want to load a file (config/routes.rb) which is inside refinerycms code.
We can’t directly require the file, as it is not in lib folder of the refinerycms-core gem
So after browsing through some refinerycms code, I found out a method
Refinery::Core.root which gave me the full path to root of refinerycms-core gem (Not the /path/to/all/gems/refinerycms-core-2.0.10/lib, which is loaded in load_path by Bundler.require)
So finally I ended up doing this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
We need that devise line to make sure devise has a warden_config object, otherwise now devise starts throwing exceptions !
But remember again, this is just hack, if you ever find out a better enough solution, please drop me a mail or just comment down here.