Reputation: 921
I am trying to create view/controller specific Javascript in Rails 3.1. I have followed the method from Rails 3.1 asset pipeline: how to load controller-specific scripts? and http://tech.thereq.com/post/10754558724/the-rails-3-1-asset-pipeline-in-the-real-world-jquery.
This works great in my development environment. However, it fails in my production environment. I get the message, ActionView::Template::Error (users.js isn't precompiled).
My user.js.coffee file inside the .../app/assets/javascript directory contains
//= require i18n/grid.locale-en
//= require jquery.jqGrid.min
//
//= require grid_object.js
My index.html.haml file inside .../app/views/users contains
- javascript 'users'
...
My application_helper contains
def javascript(*files)
content_for(:head) { javascript_include_tag(*files) }
end
My application layout file contains
%= yield(:head) %>
Lastly, my application.js file inside .../app/assets/javascript contains
//= require jquery
//= require jquery-ui
What am I missing?
Upvotes: 2
Views: 689
Reputation: 921
I decided to use a postfix (i.e. '_pc') for all my controller/view specific javascript that needed to be pre-compiled. The required changes are:
Inside my view, I used:
- javascript require 'users_pc'
I renamed my users.js.coffee file to users_pc.js.coffee
Lastly, I updated my .../config/environments/production.rb file to contain
- config.assets.precompile << '*_pc.js'
Upvotes: 1