why am I getting a mass assignment error when my column is on my attr_accessible list

There are several related questions to this one. But none of the answers address my situation.

I am getting this error on my localhost when trying to create a new policy.

Can't mass-assign protected attributes: starts_on

In my policy.rb model though I have this:

class Policy < ActiveRecord::Base

belongs_to :policy_type

attr_accessible :starts_on,
                :ends_on,
                :i_agree_privacy_policy,
                :license,
                .
                .
                .etc...

validates:starts_on, :presence => true

def self.init(user, policy_type, load_user_profile = true)
    attributes = {
        :user => user,
        :policy_type => policy_type,
        :starts_on => Date.today
    }
    policy_type.policy_class.constantize.new(attributes)
end

etc...
end

The form is for insurance so its huge but its also not important here since I am creating the starts_on here with Date.today. Really stumped here and I've spent several hours on google the last couple of days to figure out why this is happening.

Answers


You're probably getting the "Can't mass assign" error on the actual class that policy_type.policy_class resolves to, not on Policy.

I would check whatever class policy_type.policy_class points to, and try adding starts_on to attr_accessible there.


Need Your Help

Compare two strings character by character in C

c string

I have one 'simple' (I hope) question. I am actually coding some little program and I need to compare two strings, same length, but different letters like

How can I make my VS2008 x86 installer install x64 assemblies on x64?

visual-studio-2008 installation windows-installer x86 64bit

I'm using the VS2008 installer (plus a custom Orca action) to create an installer for my .NET product.