Reputation: 65
My javascript works in local environment but not on Heroku.
The file is "destroy.js.erb" and it is located in view, same as index.html.erb (where javascript is used).
Here are the Heroku logs that I suspect where the error occurred:
2014-01-07T03:34:31.980578+00:00 app[web.1]:
2014-01-07T03:34:31.980578+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets/application-ed404d2f6b226ecfcf36b0b53bc646a7.js"):
2014-01-07T03:34:31.980578+00:00 app[web.1]: I, [2014-01-07T03:34:31.976356 #2] INFO -- : Started GET "/assets/application-ed404d2f6b226ecfcf36b0b53bc646a7.js" for 24.24.157.128 at 2014-01-07 03:34:31 +0000
2014-01-07T03:34:31.980578+00:00 app[web.1]: F, [2014-01-07T03:34:31.977454 #2] FATAL -- :
2014-01-07T03:34:31.980578+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
destroy.js.erb: (JavaScript is called delete user via fadeOut instead of page refresh)
$('#<%= dom_id(@user) %>').fadeOut();
index.html.erb:
<h3>All Users List</h3>
<head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> </head>
<% @users.each do |user| %>
<%= div_for user do %>
<%= link_to "User #{user.firstname} #{user.lastname}", user %>
<font color='green'><%= user.email %></font>
<div class="actions">
<td><%= link_to 'View Detail', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Delete User', user_path(user), method: :delete, remote: true, data: {confirm: 'Are you sure?'} %></td>
<p>
</div>
<% end %>
<% end %>
<%= link_to 'Create New User', new_user_path %>
layouts/application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>Crud</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
EDIT: Here is the app: http://sheltered-sea-8479.herokuapp.com/users
Does anyone know how to resolve this issue?
Thank you!
Upvotes: 0
Views: 2093
Reputation: 13354
I'll preface what I'm about to say with I know this idea is like mass destruction for a small problem, but I beat my head against the wall for days with this problem and this was the only way I found to fix it...
Try increasing the config.assets.version
value in your config/production.rb
file. It will expire all assets for your app, but it will regenerate the md5 fingerprint for that file as well, and should help the app recognize it again.
Example:
Change config.assets.version = '1.0'
to config.assets.version = '1.1'
.
UPDATE
It sounds like Heroku isn't precompiling your assets for you. Try to run: RAILS_ENV=production bundle exec rake assets:precompile
then redeploy. If you're not using bundler
, you can remove the bundle exec
from the above command.
Upvotes: 2