【问题标题】:Scoping association in RailsAdminRailsAdmin 中的范围关联
【发布时间】:2013-04-19 18:48:21
【问题描述】:

我尝试确定关联范围,以便用户在编辑关系时看不到已发送的提醒。但是,我确实希望它们在“显示”视图中看到,而不是在“编辑”视图中。

我无法让范围在每个字段的基础上工作。我可以使用 proc 确定整个 has_many 调用的范围,但这不会让我在“显示”页面上显示结果,因为它是模型范围的。这是我当前的代码,基于 RailsAdmin wiki 似乎不起作用:

  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

【问题讨论】:

    标签: ruby-on-rails scope associations rails-admin


    【解决方案1】:
    associated_collection_cache_all true
    

    应该有帮助

    【讨论】:

      【解决方案2】:

      也许尝试将您的代码放在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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-10
        • 1970-01-01
        • 2015-07-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多