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

3 Answers 3

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.

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

Comments

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

Comments

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.

3 Comments

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?
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?
Thanks again for your time and being patient with me.

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.