Permalink
Browse files

assert that the environment is initialized under rails 3.1.1 (rc3 and…

… up, does not function under rc2)
  • Loading branch information...
1 parent 97d5c24 commit 5b28cd9df93f2ed78533427452a7421156a5c276 @mjtko mjtko committed Oct 3, 2011
Showing with 10 additions and 1 deletion.
  1. +1 −1 app/assets/javascripts/js-routes.js.erb
  2. +9 −0 lib/js_routes.rb
@@ -1 +1 @@
-<%= JsRoutes.generate %>
+<%= JsRoutes.assert_usable_configuration! && JsRoutes.generate %>
View
@@ -47,6 +47,15 @@ def generate(opts = {})
def generate!(opts = {})
new(opts).generate!
end
+
+ # Under rails 3.1.1 and higher, perform a check to ensure that the
+ # full environment will be available during asset compilation.
+ # This is required to ensure routes are loaded.
+ def assert_usable_configuration!
+ @usable_configuration ||= Rails.version >= "3.1.1" &&
+ Rails.application.config.assets.initialize_on_precompile ||
+ raise("Cannot precompile js-routes unless environment is initialized. Please set config.assets.initialize_on_precompile to true.")
+ end
end
#

0 comments on commit 5b28cd9

Please sign in to comment.