Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

route submit button to custom path

I am trying to route a submit button to a specific path (page), but I believe my syntax is not accurate.

This is what I have now:

<%= submit_tag('Next (Step 2 of 3)'), customer_index_path %>

I am getting the error:

/Users/anmareewilliams/RailsApps/GroupOrderingCopy/app/views/products/index.html.erb:18: syntax error, unexpected ',', expecting ')'
...bmit_tag('Next (Step 2 of 3)'), customer_index_path );@outpu...
...  

I tried this as well:

<%= submit_tag'Next (Step 2 of 3)', customer_index_path %> 

and got no errors in the text editor, but got a Rails error that said:

undefined method `stringify_keys' for "/customer/index":String

How can I accomplish routing my submit to a specific path?

like image 593
anmaree Avatar asked Dec 18 '13 19:12

anmaree


1 Answers

You don't include path in submit_tag. You need to define the path in your form's action.

<%= form_tag(customer_index_path) do %>
  <%= submit_tag 'Next (Step 2 of 3)' %> 
<% end %>

This should submit the form to customer_index_path.

Update:

To submit a GET request to #customer_index_path, you need to update the form_tag declaration as follows:

<%= form_tag(customer_index_path, method: :get) do %>
  <%= submit_tag 'Next (Step 2 of 3)' %> 
<% end %>
like image 140
vee Avatar answered Nov 12 '22 03:11

vee