0

I'm having a bit of trouble getting my javascript function that is compiled by the Asset Pipeline to work in production. It is working fine in development.

Javascript

# app/assets/javascript/subscribe.js

$(function() {
  $('#fat-btn').click(function() {
    var btn = $(this)
    btn.button('loading')
    setTimeout(function () {
      btn.button('reset')
    }, 2000)
  });
});

My view

# app/assets/subscribe.html.erb

<div class="subscribe">
  <%= form_tag subscribe_path, class: "form-inline" do %>
      <%= text_field_tag :email, nil, :type=>"email", :placeholder => 'Your email address' %>
      <%= button_tag "Go", id: "fat-btn", class: "btn", data: { "loading-text" => "loading...", "toggle" => "button"} %>
  <% end %>
</div>

My Application Javascript

# app/assets/javascript/application.js

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .

Any help is much appreciated it. Thank you

Wasabi Developer
  • 3,523
  • 6
  • 36
  • 60

3 Answers3

1

This happened to me before and in my case I was calling multiple instances of JQuery. So:

  • Make sure you're not calling multiple instances of JQuery.

  • If you are using coffeescript and have a syntax error (I had extra spaces in my case) in development all can go well but in producion it will not. Again, the console's log when you precompile should point out any issues if there are any.

  • See if there are any errors in Firebug when you are in development
    and production
    .

  • If all that fails you can try to clean and precompile your assets
    again.

Silver
  • 693
  • 1
  • 10
  • 27
1

please check error that

hi budy please do following changes in file before deploy to production mode

------enviorment.rb-----

::ActiveSupport::Deprecation.silenced = true

------Production.rb-------

config.assets.compile = ['*.js', '*.css']
config.active_support.deprecation = :silence

-------application.rb-------

config.assets.enabled = true
config.assets.initialize_on_precompile = false
Bajirao Pheshwe
  • 504
  • 2
  • 10
0

Could you check network console in your browser while loading page in production mode? It seems some assets has not been loaded.

If so, it looks like config.serve_static_assets set to false (by default in production mode) in your rails environment config. Check config/environments/production.rb file.

icanhazbroccoli
  • 1,035
  • 9
  • 15
  • Hi 4pcbr, thanks for your response. The network console has the function compiled in application.js; would renaming subscribe.js to it's controller .coffee file help with anything? – Wasabi Developer Apr 22 '13 at 08:14
  • No, it doesn't matter. Could you provide more info about the error you catch? What exactly happens and do you see it while running your dev server under production environment? – icanhazbroccoli Apr 22 '13 at 10:08
  • Thanks again for your time and being patient with me. – Wasabi Developer Apr 26 '13 at 01:25