ruby on rails - Adding many photos to a record. Can't mass-assign protected attributes: -


i'm trying add photos app using paperclip. mug can have many photos.

when try save new mug error:

activemodel::massassignmentsecurity::error in mugscontroller#create

can't mass-assign protected attributes: mugphoto

mug.rb

class mug < activerecord::base   attr_accessible :name, :mugphotos_attributes   has_many :mugphotos   accepts_nested_attributes_for :mugphotos, :allow_destroy => true end 

mugphoto.rb

class mugphoto < activerecord::base   belongs_to :mug    has_attached_file :mugphoto,      :styles => {         :thumb => "100x100#" } end 

mug new.html.erb

<%= form_for @mug, :html => { :multipart => true } |f| %>    <p>name: <br>   <%= f.text_field :name %></p>    <%= f.fields_for :mugphoto |photo| %>     <p>photo: <br>     <%= photo.file_field :mugphoto %></p>   <% end %>         <div class="button"><%= submit_tag %></div> <% end %> 

mugs_controller

class mugscontroller < applicationcontroller    def new     @mug = mug.new   end    def create     @mug = mug.create(params[:mug])     if @mug.save       flash[:notice] = 'mug added'       redirect_to mugs_path     else       render :action => :new     end   end end 

you need add attr_accessible :mugphoto in mugphoto.rb


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -