Can't mass-assign protected attributes: avatar #202

chrise86 opened this Issue Jun 17, 2012 · 2 comments


None yet

4 participants


I've added an "avatar" to my user model (Devise) and am getting the error Can't mass-assign protected attributes: avatar

In my user model I have added:

attr_accessible :avatar_uid, :avatar_name
image_accessor :avatar

And the form (simple_form) has :html => { :method => :put, :multipart => true } and fields:

<%= f.file_field :avatar %>
<%= f.hidden_field :retained_avatar %>
<%= f.check_box :remove_avatar %>

Adding :avatar to attr_accessible solves the mass assignment error but the fields just don't get saved in the user table.


This error occur to me too. But I added image_accessor variable to attr_accessible, and all goes good.

How does it goes when form like this?

<%= form_for(@user, :html => {:multipart => true}) do |f| %>
  <%= f.file_field :@avatar %>

  <div class="actions">
    <%= f.submit %>
<% end %>

Seems you need to specify attr_accessible :avatar instead of attr_accessible :avatar_uid.

@markevans markevans closed this Aug 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment