2013-04-25 57 views
4

我尝试限制关联的范围,以便用户在编辑关系时看不到已发送的提醒。不过,我希望他们能够在'show'视图中​​看到,但不能在'edit'视图中看到。RailsAdmin中的范围关联

我不能让范围工作在每个字段的基础上。我可以将整个has_many调用的范围限定在proc范围内,但这不会让我在'show'页面上显示结果,因为它是模型范围的。这里是我当前的代码,这似乎不是基于RailsAdmin维基工作:

group :reminders do 
    label 'Reminders' 
    field :reminders do 
     active true 

     associated_collection_scope do 
     Proc.new { |scope| 
      scope = scope.where(sent: false) 
     } 
     end 

    end 
    end 

回答

0
associated_collection_cache_all true 

它应该帮助

1

也许尝试抛出上述的edit do ; end块的内部代码。所以,会变成:

edit do 
    group :reminders do 
    label 'Reminders' 
    field :reminders do 
     active true 

     associated_collection_scope do 
     Proc.new { |scope| 
      scope = scope.where(sent: false) 
     } 
     end 

    end 
    end 
end