trestle
trestle copied to clipboard
How can I call a custom action from ajax when form input change (onchange js)
I have a custom action that I need to trigger to populate a select in a :new form.
I create a custom function and route that return JSON when its called:
def get_free_slots
# some stuff here
render json: data
end
routes do post get_free_slots, on: :member end
I am able to trigger the action with a link_to function:
link_to "Get Free Slots", admin.path(:get_free_slots, id: 1, params: {"date": project[:start_date].to_s}), method: :post, class: "btn btn-info"
Now, I need to call get_free_slots route with AJAX, and use the retrieved JSON to populate a "select" form field.
Can you explain to me how to achieve this?