使用Machinist,是否有某种方法可以定义蓝图,使其继承其他蓝图的属性?我已经查看了我找到的所有文档和示例,但我还没有看到这种情况发生。
我想做这样的事情:
User.blueprint do
name
email
end
User.blueprint(:admin) do
is_admin { true }
end
User.blueprint(:editor) do
is_editor { true }
group
end
User.blueprint(:contributor) do
is_editor { true }
end其中它们都继承了第一个蓝图中的name/email,而:contibutor蓝图继承了:editor蓝图中的group属性。
这个是可能的吗?
发布于 2011-03-03 06:38:53
是的,这在一定程度上是可能的,至少在Machinist 1上是这样(我还没有尝试过Machinist 2)。您只能从给定类的默认蓝图继承属性。
您的语法是正确的,请参阅https://github.com/notahat/machinist/tree/1.0-maintenance中的“命名蓝图”,但您的蓝图贡献者直接继承自默认的用户蓝图。您必须在贡献者蓝图中手动设置组属性。
创建管理员用户的语法为User.make(:admin)。
https://stackoverflow.com/questions/5171601
复制相似问题