Reputation: 47
am new in ruby on rails and please i want to execute a method in my controller or in my helper when i click this button, so any ideas for that?
<%= button_to 'Export POINT', :action => :create_file_txt %>
Thanks
Upvotes: 1
Views: 466
Reputation: 76784
Route
button_to
is basically a link:
Generates a form containing a single button that submits to the URL created by the set of options. This is the safest method to ensure links that cause changes to your data are not triggered by search bots or accelerators. If the HTML button does not work with your layout, you can also consider using the link_to method with the :method modifier as described in the link_to documentation
You need to send it to a route:
#config/routes.rb
get "your_route", to: "controller#action"
This will give you the ability to use the URL helpers to define the path & get the button to work:
<%= button_to 'Export POINT', your_route_path %>
Link
As per the comments, you would also benefit from using link_to
for this as well:
<%= link_to 'Export POINT', your_route_path %>
Upvotes: 1