How to call a controller method from a button in rails 4

前端 未结 5 532
日久生厌
日久生厌 2020-12-15 17:30

So I feel really stupid right now, but I can\'t seem to find an answer.

So I have a method which needs to be called EXACTLY once, and since this is only the experime

5条回答
  •  囚心锁ツ
    2020-12-15 18:27

    <%= form_tag home_action_path, method: :post do %>
      <%= submit_tag 'Call Action' %>
    <% end %>
    

    could also use a link

    <%= link_to 'Call Action', home_action_path, method: :post %>
    

    or you can use button_to

    <%= button_to 'Call Action', home_action_path, method: :post %>
    

    in your routes

    post 'home/action'
    

提交回复
热议问题