2

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?

1
  • Fixed it by moving coffee-rails out of the assets group in my Gemfile... Thanks to : http://stackoverflow.com/questions/11926034/rails-javascript-views-not-working-in-production?rq=1 for the answer! Commented Sep 26, 2012 at 21:26

1 Answer 1

1

Fixed it by moving coffee-rails out of the assets group in my Gemfile, thanks to Rails JavaScript views not working in production.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.