Hello everyone!
I have a partial file called _more_contacts.js.coffee in app/views/contacts/
This partial is rendered via an Ajax call to the ContactsController, and update another partial (_more_contacts.html.erb) in a view:
Ajax call:
<%= link_to "blah", more_contacts_path(@smthg) , method: :post, remote: true, id: "more_contacts", data: {last: raw(@id)} %>
Controller code:
def more_contacts
@contacts = Contact.search(params)
respond_to do |format|
format.js { render partial: "more_contacts" }
end
end
JS Partial code:
$('#more_contacts_table').append('<%=j render partial: "more_contacts", formats: [:html] %>')
HTML Partial:
<% @contacts.each do |contact| %>
<tr>
<td><%= link_to contact.company, contact_path(contact.id) %></td>
<td><%= contact.email %></td>
</tr>
<% end %>
Note that I struggled a couple of hours to find out that it shouldn't have the .erb extension, even though it contains some ruby code...
Anyway, everything works great in development, but I can't make it works in production :(
I have tried the following in my config/environments/production.rb
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.assets.precompile += %w( contacts/more_contacts.js app/views/contacts/more_contacts.js )
config.assets.precompile << "contacts/_more_contacts.js"
config.assets.precompile << "#{Rails.root}/app/views/contacts/_more_contacts.js"
config.assets.precompile << "#{Rails.root}/app/views/contacts/_more_contacts.js.coffee"
config.assets.precompile << "#{Rails.root}/app/views/contacts/more_contacts.js"
config.assets.precompile << "#{Rails.root}/app/views/contacts/more_contacts.js.coffee"
But when I run my rake task to compile the assets, more_contacts.js is nowhere to be found (public/assets/manifest.yml or public/assets/) and the Ajax call fails...
I'm stuck here :( Any idea, anyone?
http://stackoverflow.com/questions/11926034/rails-javascript-views-not-working-in-production?rq=1for the answer!