我正在尝试将提交按钮路由到特定路径(页面),但我相信我的语法不准确.
这就是我现在拥有的:
<%= submit_tag('Next (Step 2 of 3)'), customer_index_path %>
我收到错误:
/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... ...
我也尝试过这个:
<%= submit_tag'Next (Step 2 of 3)', customer_index_path %>
并在文本编辑器中没有错误,但得到一个Rails错误,说:
undefined method `stringify_keys' for "/customer/index":String
如何完成将提交路由到特定路径?
你不包括path
在submit_tag
.你需要在你定义的路径form
的action
.
<%= form_tag(customer_index_path) do %> <%= submit_tag 'Next (Step 2 of 3)' %> <% end %>
这应该提交表格customer_index_path
.
更新:
要提交GET
请求#customer_index_path
,您需要更新form_tag
声明如下:
<%= form_tag(customer_index_path, method: :get) do %> <%= submit_tag 'Next (Step 2 of 3)' %> <% end %>