0

I am trying to use some Jquery witihin a rails application. This is my first time using Jquery in rails and I cannot seem to get it to work. I am using rails4 and this is what my code looks like

I have a pages controller with an index action

index action

def index
  respond_to do |format|
   format.html
   format.js
  end
end

pages.js

$(document).ready(function(){
$('.button').click(function(){
    $(this).fadeOut('slow);
  });
});

index.html.erb

 <button class="button">Clickme</button>

However I get no response, am I missing something here ?

1
  • Hi. You have a ' missing from the fadeOut method. Is that a typo? Commented Sep 7, 2013 at 11:17

2 Answers 2

1

Rails4 uses turbolinks.

So in coffescript your code should be:

pages.js.coffee

ready = ->
  $('.button').click -> 
    $(this).fadeOut('slow')


$(document).ready(ready)
$(window).bind('page:change', ready)
Sign up to request clarification or add additional context in comments.

Comments

0

Is your controller "pages"? Where is "pages.js" located?

If "pages" is the controller, and "pages.js" is in /app/assets/javascripts/ then I am of no help. But in my test app, I placed your javascript in the .js file for the controller, in /app/assets/javascripts/ and the button fades out like you expected.

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.