I have the following route:
resources :foods do
collection do
post :f01a
end
end
and controller:
def f01a
@user = User.find(params[:id])
@eat = Eat.find_by_user_id(@user)
@eat.toggle!(:f01)
redirect_to @user
end
and view:
<%= button_to "add f01a", send(:"f01a_foods_path", id: @user.id), class: "btn btn-large btn-primary" %>
My goal is to call this controller action from a JavaScript onclick instead of using an HTML button.
The problem is that, currently, I can double click on the button and execute the code twice while the page is rendering. It's my understanding that JavaScript or AJAX fixes this.