未允许的参数错误 - 使用Devise和Active Admin进行Rails 4

时间:2016-09-19 15:20:50

标签: ruby-on-rails devise activeadmin

我在Rails 4和Devise上创建了简单的应用程序(用于注册和登录)。

问题:无法在创建或编辑用户中保存country_id参数。

注意:仅当我尝试从Active Admin面板创建/编辑用户时才会出现问题。如果我从我网站的公共场所注册用户,一切正常。

我的表单在user.rb文件中,带有许可证参数:

 form do |f|
        f.inputs "User Details" do
           f.input :email
           f.input :name, :input_html => { :class => 'autogrow', :rows => 1, :cols => 2, :maxlength => 120 }
           f.input :country
           f.input :password,:input_html => { :class => 'autogrow', :rows => 1, :cols => 2, :maxlength => 120 }
           f.input :password_confirmation, :input_html => { :class => 'autogrow', :rows => 1, :cols => 2, :maxlength => 120 }
           f.input :role, as: :radio, collection: {Simple_user: "user"}
           f.input :bypass_humanizer, :value=> true,:as => :hidden
        end
        f.actions
    end

     permit_params :email, :password, :country_id,:bypass_humanizer,:password_confirmation, :role,:user, :in_blacklist, :admin_confirmed, :name

我在admin / user.rb文件中的创建操作:

   def create      
       @user = User.new(user_params) 

    if @user.save  
       flash[:notice] = 'User was successfully created.' 
       redirect_to admin_user_path(@user)  

    else
       redirect_to :back
       flash[:notice] = 'Error accured. Please, check your data.' 
   end

    end

我的日志文件:

Started POST "/admin/users?locale=ru" for 85.254.76.28 at 2016-09-19 18:03:42 +0300
Processing by Admin::UsersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"tmR9OsaNKREZb0l7J6gJb0E4G3bkmqSUrlduxMOVyQ8=", "user"=>{"email"=>"test7@individualki.eu", "name"=>"test7", "country_id"=>"1", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "role"=>"user", "bypass_humanizer"=>""}, "commit"=>"Create User", "locale"=>"ru"}
  [1m[36mCountry Load (0.5ms)[0m  [1mSELECT  `countries`.* FROM `countries`  WHERE `countries`.`id` = 1 LIMIT 1[0m
  [1m[35mRegion Load (0.6ms)[0m  SELECT `regions`.* FROM `regions`  WHERE `regions`.`country_id` = 1
  [1m[36mPartner Load (0.5ms)[0m  [1mSELECT  `partners`.* FROM `partners`  WHERE `partners`.`id` = 1 LIMIT 1[0m
  [1m[35mUser Load (0.7ms)[0m  SELECT  `users`.* FROM `users`  WHERE `users`.`id` = 169  ORDER BY `users`.`id` ASC LIMIT 1
**Unpermitted parameters: country_id**
  [1m[36m (0.4ms)[0m  [1mBEGIN[0m
  [1m[35mUser Exists (0.4ms)[0m  SELECT  1 AS one FROM `users`  WHERE `users`.`email` = BINARY 'test7@individualki.eu' LIMIT 1
  [1m[36mCACHE (0.0ms)[0m  [1mSELECT  1 AS one FROM `users`  WHERE `users`.`email` = BINARY 'test7@individualki.eu' LIMIT 1[0m
  [1m[35mUser Load (0.6ms)[0m  SELECT  `users`.* FROM `users`  WHERE `users`.`confirmation_token` = '08bf7322064e9569421c784e4fc4199be6ae20e4bc5ff960fdb49980fe0d018f'  ORDER BY `users`.`id` ASC LIMIT 1
  [1m[36mSQL (0.7ms)[0m  [1mINSERT INTO `users` (`confirmation_sent_at`, `confirmation_token`, `created_at`, `email`, `encrypted_password`, `name`, `role`, `updated_at`) VALUES ('2016-09-19 18:03:42', '08bf7322064e9569421c784e4fc4199be6ae20e4bc5ff960fdb49980fe0d018f', '2016-09-19 18:03:42', 'test7@individualki.eu', '$2a$10$.NQgfnCbuH0ZUErcuL7vbO5x6BLQTZkZ9wiQFVkJvkJnCfc9ab38O', 'test7', 'user', '2016-09-19 18:03:42')[0m
  Rendered devise/mailer/confirmation_instructions.html.erb (4.5ms)

我尝试了什么:

1)仔细检查permit_params行的users_controller,registration_controller和admin / user.rb文件的每个地方,以便包含country_id。

2)每次代码更改后重新启动服务器

3)更改了表格,因此f.input:country将成为f.input:country_id所以我可以填写country_id的简单数字。

0 个答案:

没有答案