سؤال

To allow me to quickly filter records in ActiveAdmin i've defined scopes on my model. I have "shipped" and "unshipped" scopes as below. For some reason the "Shipped" scope is working as expected and shows the number of shipped items but the "Unshipped" scope doesn't do anything, it doesn't seem to know what is unshipped. It seems that i have to check and then uncheck "Shipped" checkbox in order for it to know that it's unshipped??

ORDER MODEL

class Order < ActiveRecord::Base

    scope :shipped, where(:shipped => true)
    scope :unshipped, where(:shipped => false)

end

ADMIN ORDER MODEL

ActiveAdmin.register Order do

    scope :all, :default => true
    scope :shipped
    scope :unshipped

index do
    selectable_column
    column "Status", :sortable => :shipped do |s|
      status_tag((s.shipped? ? "Shipped" : "Unshipped"), (s.shipped? ? :ok : :warning))
    end
end
end

Can anyone see what the problem is? Many Thanks

هل كانت مفيدة؟

المحلول 2

Realised that shipped was not by default set to false so fixed the issue by doing so in the Orders table.

نصائح أخرى

Is that the actual code from your model?

It should be:

scope :shipped, -> { where(shipped: true) }
scope :unshipped, -> { where(shipped: false) }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top