【问题标题】:Unpermitted parameter: locale不允许的参数:locale
【发布时间】:2015-02-25 22:24:25
【问题描述】:

在我的 Rails 应用程序中使用 ActiveAdmin 登录后,我遇到了一些“语言环境”问题。我如何允许语言环境的参数?

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

config/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

【问题讨论】:

    标签: ruby-on-rails-4 devise permissions activeadmin


    【解决方案1】:

    您必须在活动管理控制器中定义 allowed_pa​​rams

    这是我的解决方法:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      相关资源
      最近更新 更多