这是在 中application.html.erb
,它适用于我应用程序中 95% 的页面:
<% ['usd', 'eur', 'aud'].each do |currency| %>
<%= form_with url: {controller: :home, action: :currency_select}, method: :post do |currency_form| %>
<%= currency_form.hidden_field :preferred_display_currency, value: currency %>
<%= currency_form.submit currency, class: "btn-info shadow-none" %>
<% end %>
<% end %>
但是当我访问某个视图时,在页面加载之前,它会给出这个错误:
ActionView::Template::Error (No route matches {:action=>"currency_select", :controller=>"users/home"}):
191:
192: <%= form_with url: {controller: :home, action: :currency_select}, method: :post do |currency_form| %>
193: <%= currency_form.hidden_field :preferred_display_currency, value: currency %>
194: <%= currency_form.submit currency, class: "btn-info shadow-none" %>
195: <% end %>
196:
197: <% end %>
我很确定与:controller=>"users/home"
(应该只是在哪里:controller=>"home"
)有关
为什么表单突然对控制器感到困惑?