2

I have a following function in my _new.html.erb. I would like to call a controller when the element_id_placeholder is changed:

 <script type="text/javascript">

    // When DOM loads, init the page.
    $(function() {
      // Executes a callback detecting changes with a frequency of 1 second
      $("#id_element_placeholder").observe_field(1, function( ) {                                       
        alert('Change observed! new value: ' + this.value );
        // call controller 

      });
    });

  </script>

I'm using rails 3

1 Answer 1

5

Use jQuery's ajax method:

$.ajax({
type: "GET",
url: "/articles/" + $(this).attr('value'),
success: function(data){}
});

http://api.jquery.com/jQuery.ajax/

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

1 Comment

Thanks that works but it goes to my controller/view. How would I call some method which would return me back the model Object or even a json object that I can build as part of that method?

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.