3

I want to call the controller method in ajax url to dynamically populate the dropdown based on value from another dropdown. The value I am getting is string, when I call this method using ajax url it always refers to 'show' method. My ajax call

$('#users').change(function() {
  url: '/users/update_groups',
  data: {name: $(this).val()},
  success: function (data) {
    alert(data);
  }
});

In my users_controller.rb

def update_groups user_name
  # returns list of groups
end

How to call this method using ajax url?

1 Answer 1

4
$("#users").change(function() {
  $.ajax({
      url: "users/update_groups",
      type: "POST",
      data: {name: $(this).val()},
      success: function (data) {
      alert(data);
      }
  });
});

try the above code once it may work and let me know.....will try to help some other way if it don't work.....

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

2 Comments

thanks .for your reply. this code also doesn't call the update_groups method. In parameter id is passing and not name
it should work , will u give detailed description of your problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.