我在登录后使用ActiveAdmin在我的Rails应用程序中使用“locale”时遇到了一些问题。我如何允许params用于现场?
Started GET "/admin?locale=ru" for ::1 at 2015-02-25 23:05:19 +0100
Processing by Admin::DashboardController#index as HTML
Parameters: {"locale"=>"ru"}
AdminUser Load (0.2ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = ? ORDER BY "admin_users"."id" ASC LIMIT 1 [["id", 2]]
Unpermitted parameter: locale
Redirected to http://localhost:3000/admin?locale=ru
Completed 302 Found in 6ms (ActiveRecord: 0.2ms)
我的application_controller.rb
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
def default_url_options(options={})
{ :locale => I18n.locale }
end
配置/ application.rb中
config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# Do not swallow errors in after_commit/after_rollback callbacks.
#config.active_record.raise_in_transactional_callbacks = true
config.i18n.enforce_available_locales = true
config.i18n.default_locale = :ru
app / admin / admin_user.rb
permit_params :email, :password, :password_confirmation, :role, :locale
答案 0 :(得分:0)
您必须在活动管理控制器中定义allowed_params
这是我的修复:
ActiveAdmin.register Model do
controller do
def permitted_params
params.permit(:utf8, :_method, :authenticity_token, :locale, :commit, :id,
model: [:description, :price, :name, :limit, :shipping, :slug, :project_id]
)
end
end
end
'Model'是模型的名称,不要忘记包含外来参数:utf8,:_ method,:authenticity_token