0

I'm using haml and before i haven't any experience with haml. I'm fire ujs call whose code are below

  = link_to "this is the best",cast_vote_cast_votes_path(job_application.id),:id => job_application.id ,:remote => true ,:class => 'btn btn-primary best-button'

after this call is fire my function "cast_vote" execute and i have templete with name "cast_vote.js.erb". In which i just want to execute alert of js. But alert is not executing why?

i don't know. Any help please..

3
  • What does your cast_vote.js.erb file look like? Commented Feb 12, 2013 at 16:20
  • it is just one line alert("ok") Commented Feb 12, 2013 at 16:24
  • this is response of ajax call <div class='container container-width'> alert('ok') </div> Commented Feb 12, 2013 at 16:25

2 Answers 2

2

Try adding this to your haml template:

:javascript
  $(document).ready(function() {
    $(".best-button").click(function() {
       alert("ok");
    });
  });
Sign up to request clarification or add additional context in comments.

1 Comment

This will show the alert, but not as a response to the ajax request.
1

You need to configure the success callback for the remote ajax request to handle the response. Add this script to your haml file:

$('.best-button')
  .bind('ajax:success', function(event, data, status, xhr){ 
    eval(data.response);
  });

And change your js.erb to return a json object in the form {response: 'alert("ok")'}.

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.