I'm pretty new to Ruby on Rails and having a hard time using Ajax calls in rails and I was hoping someone could help me out.
$.ajax({
url: 'organizations/set_all_priorities',
data: {ticket1: ticket1, ticket2: ticket2, ticket3: ticket3},
method: "PUT"
});
This is my Ajax call. I have 3 ticket vars containing an integer. The method calls my organization controller's method set_all_priorities.
The set_all_priorities method in my organizations_controller looks like this:
def set_all_priorities
puts "I am now in set_all_priorities"
org = Organization.find_by(:zendesk_organization_id => Ticket.find_by(:ticket_id => params[:ticket1]).organization_id)
org.update_all(:priority1 => params[:ticket1])
org.update_all(:priority2 => params[:ticket2])
org.update_all(:priority3 => params[:ticket3])
org.save
end
end
Unfortunately it is not even calling the method as I cannot find my puts command anywhere when calling my Ajax function.
Finally, in my routes I have the following line:
put 'organizations/set_all_priorities', :to => 'organizations#set_all_priorities'
The error I am getting is this: ActiveRecord::RecordNotFound (Couldn't find Organization with 'id'=set_all_priorities):
It seems like my update method is being called, but seeing as I have defined my own method in the controller and it's not being called that makes no sense to me.
If anybody knows the solution to this that would be awesome. Thanks everyone!