【发布时间】:2016-06-05 04:04:08
【问题描述】:
我正在尝试在 rails 4 中制作应用程序。
我想在模型中编写一个方法来检查所有属性是否为真。
我正在尝试:
def ready_to_go
if
[ payment == true,
&& terms == true
&& identification == true
&& key_org == true
&& key_business == true
&& docs == true
&& funding == true
&& contract == true
&& governance == true
&& internal == true
&& preferences == true
&& address == true
&& interest == true ]
end
end
谁能看出这是怎么回事?
【问题讨论】:
-
define 错了,能不能简洁点?或者它不工作?我不明白为什么你有数组语法
[和]或者为什么它在if中没有任何内容。如果您只想返回 true 或 false,则删除 if 和数组语法 -
而不是在模型
self.attributes中尝试这样来获取该模型的所有属性。
标签: ruby-on-rails methods