Reputation: 441
<%= form_tag home_action_path, method: :post do %>
<%= submit_tag 'Call Action' %>
<% end %>
I want it like
<%= link_to 'Call Action', home_action_path, method: :post %>
OR
<%= button_to 'Call Action', home_action_path, method: :post %>
I have a method which needs to be called EXACTLY once, and since this is only the experimental phase, I decided that a simple button should suffice. However, I can't seem to find out how to / if I can simply call the method from a button click.
The method is in home_controller.rb and the button is in index.html.erb
Upvotes: 0
Views: 85
Reputation: 23949
You don't call methods on controllers, you send requests to URLs/endpoints in your application, which result in controller methods being invoked.
What's wrong with what you posted?
<%= link_to 'Call Action', home_action_path, method: :post %>
That seems fine.
Upvotes: 2