使用redirect_to参数更改语言

时间:2015-10-28 10:43:38

标签: ruby-on-rails

当用户编写www.myweb.com/en-GB/时,我需要更改网页中的param语言,默认语言为es-ES。

我正在重定向:

params[:language] = session[:language]

redirect_to params

我的所有路线工作正常,除了一条,我不知道为什么。

当我尝试使用此参数重定向时:

{:action=> "index" ,:controller=>"bt/contact_center", :language=>"es-ES"}

我在我的程序中使用了Engine。当我尝试重定向到没有main_app的路由时,我收到如下错误:

*** NameError Exception: undefined local variable or method contact_center_index_path' for #<Bt::ContactCenterController:0x007f98338f7348>

如果我使用main_app.route,它可以正常工作:

(rdb:1) main_app.contact_center_index_path
"http://localhost:3000/es-ES/contact_center"

当我尝试使用redirect_to params时,程序正在调用contact_center_index_path而不是main_app.contact_center_index_path,我不知道如何修复它。

我需要做类似的事情:

reditect_to main_app(params) or redirect_to main_app.controller_name_path(params)

这是我的定义路线:

mount Bt::Engine => '/'
  scope '/:language' do 
     resources :contact_center, controller: "bt/contact_center", :only => [:index] do
        collection do 
          post :createinc
        end
    end
 end
end

耙路线:

    createinc_contact_center_index POST /:language/contact_center/createinc(.:format)                 bt/contact_center#upload_fax
    contact_center_index GET  /:language/contact_center(.:format)                            bt/contact_center#index

0 个答案:

没有答案