【发布时间】:2018-07-19 11:52:29
【问题描述】:
我设置此表单以允许我从任何视图更改应用程序的语言。不知何故(无法找出原因)当我访问我的注册视图(使用 Devise 实现)时,我不允许更改它,如果我返回上一个视图或任何其他视图,我将无法再在任何语言之间切换。
Application.html.slim
- idiomas = options_for_select(User.language_list)
.btn.btn-raised.btn-icon.btn icon_language.margin_medium_right.align_items_center
form id="language_selector" method = "GET"
= select_tag(:locale, idiomas, prompt: t('language'), class: 'btn_select')
jQuery('#locale').on('change',function(){
jQuery('#language_selector').submit();
});
Application_controller.rb
def set_locale
choosen_locale = params[:locale] if params[:locale] &&
I18n.available_locales.include?(params[:locale].to_sym)
I18n.locale = choosen_locale || I18n.default_locale
end
def default_url_options
{ locale: I18n.locale }
end
Routes.rb
scope "(:locale)", locale: /es|en/ do
resources :ajax
devise_for :users, controllers: { registrations: 'registrations', sessions: 'sessions' }
devise_for :unregisters,
class_name: 'User',
only: [],
controllers: { registrations: 'unregisters' }
devise_scope :unregister do
get "/unregisters/new", to: "unregisters#new", as: :new_unregister
post "/unregisters", to: "unregisters#create", as: :unregisters
end
namespace 'admin' do
resources :clinics, except: %i[new create destroy], constraints: { id: /\d+/ }
resources :doctors, except: %i[new create destroy], constraints: { id: /\d+/ }
resources :specializations, except: %i[new create destroy], constraints: { id: /\d+/ }
resources :treatments, except: %i[new create destroy], constraints: { id: /\d+/ }
resources :insurance_contracts, except: %i[new create destroy], constraints: { id: /\d+/ }
resources :external_contents, only: %i[index edit update], constraints: { id: /\d+/ }
resources :signed_up_users, only: %i[index edit update show destroy], constraints: { id: /\d+/ }
end
resources :appointment_steps
resources :appointments, only: %i[index]
delete 'appointment/:code', to: 'appointments#destroy', as: 'destroy_appointment'
resources :appointment_payments, only: %i[create]
resources :availabilities, only: %i[index]
resources :clinics, only: :index
resources :clinic_history, only: :index
get 'download_external_file/:document_external_id', to: 'clinic_history#download_external_file', as: 'download_external_file'
resources :clinic_documents, only: :index
resources :doctors, only: :index
resources :insurance_cards
resources :treatments, only: :index
resource :insurance_payments, only: %i[create show]
resource :passwords
root to: 'home#index'
end
如果您对出了什么问题有一点了解,请随时询问更多详细信息
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 devise