2014-06-18 222 views
0

我正在忙于通过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,它可以正常工作。然而在下拉是选择它创建我的错误中提到

回答

0

发现问题,的form_tag是期待一个POST,所以我改变

<%= form_tag store_path, class: 'locale' do %> 

<%= form_tag store_path, class: 'locale', :method => :get do %> 

和它的工作