0

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!

4
  • Use Chrome's Developer tools (or Firebug if you're using Firefox) and see what the request looks like in your local environment. Is it requesting the same path for application.js? I suspect it's not, and that may point you towards the right direction. Commented Jan 7, 2014 at 4:15
  • Hello! How do I check request path using Firebug? I'm very new to web dev. Thanks for your help! Commented Jan 7, 2014 at 4:22
  • I don't use Firefox but here's the docs: getfirebug.com/network Commented Jan 7, 2014 at 4:25
  • Nice! I see Firebug shows the application- application-ed404d2f6b226ecfcf36b0b53bc646a7.js cannot be found. But in local, it pulls the js files correctly :/ Commented Jan 7, 2014 at 4:51

1 Answer 1

2

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.

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

9 Comments

Awesome! You're my hope now. I'll give it a try and report back!
Let me know if that doesn't work. I literally spent days on this exact problem and this resolved it for me. Good luck!
Hmm I see application-ed404d2f6b226ecfcf36b0b53bc646a7.js changed to application-0b975948ea716184c402656fda6196d0.js. But still Firebug shows status 404 not found :/
Haha! I've been troubleshooting this for 6 hours now. I can't believe this is taking me so long!
I found the solution! It turned out that I had to manually include "gem 'rails_12factor'" in my Gemfile, then run Bundle Install, and push to Git, then Heroku. Thanks for your time. I wouldn't have resolved this without your help!
|

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.