我正在忙于通过PBP - 敏捷Web开发与Rails并实现本地切换器。语言环境切换器
然而,当我尝试英语和西班牙语之间切换,我得到一个错误:
No route matches [POST] "/en"
我的控制器如下:
class StoreController < ApplicationController
skip_before_filter :authorize
def index
if params[:set_locale]
redirect_to store_path(locale: params[:set_locale])
else
@products = Product.order(:title)
@cart = current_cart
end
end
end
和application.hmtl.erb的提取物,正在使用;
<div id="banner">
<%= form_tag store_path, class: 'locale' do %>
<%= select_tag 'set_locale', options_for_select(LANGUAGES, I18n.locale.to_s), onchange: 'this.form.submit()' %>
<%= submit_tag 'submit' %>
<%= javascript_tag "$('.locale input').hide()" %>
<% end %>
<%= image_tag("logo.png") %>
<%= @page_title || t('.title') %>
</div>
路由文件夹如下:
scope'(:locale)' do
resources :users
resources :orders
resources :line_items
resources :carts
resources :products do
get :who_bought, on: :member
end
root to: 'store#index', as: 'store'
end
无法弄清楚我做错了什么。如果我在URL中输入/ en或/ es,它可以正常工作。然而在下拉是选择它创建我的错误中提到
使用支架只是不强制你的路由使用区域设置的,试了一下不管怎样,仍然得到同样的问题。认为它与提交尝试发布而不是调用GET有关,但这只是一个猜测 – user2021962