2013-03-17 78 views
0

在我的选址模型,我有以下..的Rails如何当accepts_nested_attributes_for

has_many :location_polls 

,并在LocationPoll模型中,我有以下reject_if ..

has_many :poll_locations 

现在又回到了位置模型,我想在没有轮询位置的情况下拒绝位置轮询。我怎样才能做到这一点?我试了下面,它没有工作..

accepts_nested_attributes_for :location_polls, :reject_if => lambda { |a| a[:poll_locations].empty? } 

我很抱歉,如果我缺少信息来帮助你回答这个问题。我不想讨论这个问题。请让我知道是否需要更多信息。谢谢。

+1

在你的'reject_if'拉姆达,标识符“a”指向你的每个':location_polls',我不知道我是否理解这个问题,但我相信你不需要'reject_if' – sergelerator 2013-03-17 03:39:32

回答

2

如果您正在寻找可忽略任何空白:location_polls可以使用:all_blank这将创建一个进程,将拒绝所有的属性都是空白排除任何_destroy值的记录:

accepts_nested_attributes_for :location_polls, :reject_if => :all_blank 
相关问题