KayoticSully
KayoticSully

Reputation: 1400

Cant mass-assign protected attributes issue

I know all the security reasons behind why mass-assigning is bad, what I cant figure out is why my app is trying to do a mass assign.

I am just trying to create a new record of my Section model and I am getting the "Can't mass-assign protected attributes" error. Below are the possible involved models. Can someone please explain to me how this is a mass-assigning? I am new to rails, so I could be missing something very simple.

class Section < ActiveRecord::Base
  belongs_to :project
  belongs_to :type, :foreign_key => 'type_id', :class_name => 'SectionType'
  attr_accessor :order
end

class SectionType < ActiveRecord::Base
  attr_accessible :name, :template
end

class Project < ActiveRecord::Base
  has_many :sections
  attr_accessible :description, :name, :short, :status, :subtitle, :version

  def to_param
    return name.gsub(/\s+/, '%20')
  end
end

Any help would be greatly appreciated, I am new to rails and know this is probably a simple problem, but I have been trying to find an answer and can not.

Upvotes: 1

Views: 205

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107728

If you're attempting to create a new Section object and that's failing, that'd be because you don't have any attributes listed as accessible inside that model. You will need to do that, using a similar call to attr_accessible as the one you have in your Project model already.

Upvotes: 1

Related Questions