ruby-on-rails – Rails 4 – 检查所有属性是否为真的方法

我正在尝试在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

有人能看出这有什么问题吗?

最佳答案
定义方法并检查是否准备就绪的最简单方法,然后:

def ready_to_go
  [ payment, terms, identification, key_org, key_business, docs, funding, contract, governance, internal, preferences, address, interest].all?
end

转载注明原文:ruby-on-rails – Rails 4 – 检查所有属性是否为真的方法 - 代码日志