Hi, I am trying to figure out how to implement AJAX to set a session variable when a user selects from a dropdown. I have not used AJAX before.
My dropdown code is: <%= collection_select( :question, :subject_id, Subject.order(:title), :id, :title, :prompt => "Select a Subject") %>
My coffeescript is jQuery -> books = $('#question_book_id').html() $('#question_subject_id').change -> alert("Set the session[subject] now!") subject = $('#question_subject_id :selected').text() escaped_subject = subject.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1') options = $(books).filter("optgroup[label='#{escaped_subject}']").html()
I assume I create a method in users_controller to change the session variable. My question is how do I call it in the jquery code?