sti rails 注意事项

环境变量:
  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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值