我正在尝试将提交按钮路由到特定路径(页面),但我相信我的语法不准确.
这就是我现在拥有的:
<%= submit_tag('Next (Step 2 of 3)'), customer_index_path %>
Run Code Online (Sandbox Code Playgroud)
我收到错误:
/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...
...
Run Code Online (Sandbox Code Playgroud)
我也尝试过这个:
<%= submit_tag'Next (Step 2 of 3)', customer_index_path %>
Run Code Online (Sandbox Code Playgroud)
并在文本编辑器中没有错误,但得到一个Rails错误,说:
undefined method `stringify_keys' for "/customer/index":String
Run Code Online (Sandbox Code Playgroud)
如何完成将提交路由到特定路径?
你不包括path在submit_tag.你需要在你定义的路径form的action.
<%= form_tag(customer_index_path) do %>
<%= submit_tag 'Next (Step 2 of 3)' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这应该提交表格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 %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2516 次 |
| 最近记录: |