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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top