我需要编写一个方法,返回布尔值是否设置为true/false。rails,方法,我需要帮助
在我的情况下,布尔值是产品的属性。而跳过在结账过程中的一步,我需要有这种类似以下自方法工作:
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user
end
这个例子是从application_controller,并且是做在结账过程中,同样的事情,我需要在这里做。
这一次我有工作的使用方法是:
def checkout_steps
checkout_steps = %w{registration billing shipping shipping_method payment confirmation}
checkout_steps.delete "registration" if current_user
checkout_steps
end
我需要工作与上面相同的删除项的布尔值。我正试图学习如何工作,所以任何解释都非常感谢。
想法?
更可读性会是'checkout_steps.delete'shipping',除非@ product.can_be_shipped'。 – 2010-03-01 21:46:39
我想你们都走在正确的轨道上,非常感谢您的帮助。在这个问题上长时间工作(时间停止成为一个新手)。在这种情况下,我在产品上有促销属性。如果促销布尔值被选中,我不想收取运费,因此取消了运送步骤。 做你写的东西; checkout_steps.delete“shipping_method”if [email protected]在促销时返回无方法错误。这就是我认为从application_controller方法拉出来以便它可以在任何地方可用的原因。任何其他的想法? – 2010-03-01 21:56:45
您的意思是“if!@ product.promotions',复数? – meagar 2010-03-01 22:13:42