Я использую devise 4.6.1 & rails 5.2.2
Я пытаюсь разрешить :avatar
в application controller
, используя configure_permitted_parameters
, однако, когда я пытаюсь обновить пользователя черезв форме account_update
я получаю сообщение об ошибке:
Processing by RegistrationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"C3zs4PT5Ui5MCVBr6Q9S05TJi2UThwGFQ+s0kTKqb+v4JHeTrl0sfeB5p+owee3DnfJ86BkgPcfNpqgWsdPqcg==", "user"=>{"username"=>"testuser2", "email"=>"testuser2@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]", "avatar"=>#<ActionDispatch::Http::UploadedFile:0x00007f4ced47a108 @tempfile=#<Tempfile:/tmp/RackMultipart20190618-18771-b0w9jf.png>, @original_filename="category-icon.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"category-icon.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Update"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ /home/ec2-user/.rvm/gems/ruby-2.6.0/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ /home/ec2-user/.rvm/gems/ruby-2.6.0/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
Unpermitted parameter: :avatar
(0.1ms) begin transaction
↳ /home/ec2-user/.rvm/gems/ruby-2.6.0/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
(0.0ms) commit transaction
↳ /home/ec2-user/.rvm/gems/ruby-2.6.0/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
Unpermitted parameter: :avatar
Unpermitted parameter: :avatar
Unpermitted parameter: :avatar
Я попытался изменить
before_action :configure_permitted_parameters, if: :devise_controller?
на
before_action :configure_permitted_parameters
Однако, когда я это сделал, я получил ошибкуниже:
неопределенная локальная переменная или метод resource_class
для DiscussionsController:0x00007f4cee0855d8
application_controller:
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:account_update, keys: [:avatar])
end