Tuesday 15 February 2011

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


So I'm really stupid now, but I can not find any answer.

So I have a method that has to be called once, and since it is only an experimental stage, I have decided that a simple button should be sufficient. However, I do not have to figure out how / if I can call the method with just a button click.

The method is in home_controller.rb and index.html.erb

Any ideas? Or is it not something I can do?

  & lt;% = form_tag home_action_path, method:: post% & gt; & Lt;% = submit_tag 'Call Action'% ' & Lt;% end% & gt;   

can also use a link

  & lt;% = link_to 'call action', home_action_path, method :: post% & gt;   

Or you can use button_to

  & lt;% = button_to 'call-action', home_action_path, method :: post% & gt;   

In your routes

  post 'home / action'    

No comments:

Post a Comment