环境变量:
config.active_record.mass_assignment_sanitizer = :logger # :restrict
in application.rb:
config.active_record.whitelist_attributes = false
参考网址:
http://hobocentral.net/tutorials/64-single-table-inheritance-with-children
子类代码:
class Agent < Profile
has_many :phone_numbers
children :phone_numbers
# The other recipe(s) say leave the sub-class models empty, but
# I needed both these lines to make the app work.
mass_assignment_sanitizer - Defines sanitize method. Possible values are:
:logger (default) - writes filtered attributes to logger
:strict - raise ActiveModel::MassAssignmentSecurity::Error on any protected attribute update
class PhoneNumbersController < ApplicationController
hobo_model_controller
auto_actions :all
auto_actions_for :profile , :create
auto_actions_for :agent , :create
auto_actions_for :client , :create
auto_actions_for :cooperating_agent , :create
end
class Profile < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
name :string
street :string
sti_type :string
timestamps
end
attr_accessible :name, :street,:sti_type
set_inheritance_column :sti_type
has_many :phone_numbers
children :phone_numbers
end