assets:precompile failed, no routes match {controller: XXX, action: XXX} #9242

Closed
d6u opened this Issue Feb 10, 2013 · 3 comments

Projects

None yet

3 participants

@d6u
d6u commented Feb 10, 2013

Rails: 3.2.11
Ruby: 1.9.3p374

I created a js.erb assets and used url_for method in it. In order to get url_for working, I included:

<% environment.context_class.instance_eval { include ActionView::Helpers } %>
<% environment.context_class.instance_eval { include ActionDispatch::Routing } %>
<% environment.context_class.instance_eval { include Rails.application.routes.url_helpers } %>

at the top of the js.erb file, everything worked fine in development mode, and url_for method translated well into the url I need. But when I precompile assets, rails shows me

rake aborted!
No route matches {:controller=>"external", :action=>"register_event"}
  (in /Users/daiwei/localhost/_projects/the-project-cube/app/assets/javascripts/_homepage_event_form.js.erb)
/Users/daiwei/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:533:in `raise_routing_error'
/Users/daiwei/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:529:in `rescue in generate'
/Users/daiwei/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:521:in `generate'
/Users/daiwei/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:562:in `generate'
/Users/daiwei/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:587:in `url_for'
/Users/daiwei/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_dispatch/routing/url_for.rb:148:in `url_for'
/Users/daiwei/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.11/lib/action_view/helpers/url_helper.rb:107:in `url_for'
/Users/daiwei/localhost/_projects/the-project-cube/app/assets/javascripts/_homepage_event_form.js.erb:69:in `evaluate_source'
.....

This is what I had for js.erb:69

$('form[action="<%= url_for(controller: 'external', action: 'register_event') %>"]').on('submit', function(event) {

Routes should be fine, because everything worked fine everywhere else, even in live compile with production mode. The error only occurs in precompiling.

@schneems
Member

Did you disable loading the app on asset precompile? If so you won't have controllers loaded. This looks more like a stack overflow question than a bug report.

@rafaelfranca
Member

Yes. Agree with @schneems. I'm closing it know, but let us know if it is still occurring.

@d6u
d6u commented Feb 21, 2013

@schneems Thank you, I changed config.assets.initialize_on_precompile = true and everything worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment