Skip to content

Index page filtering ignores the current scope #3665

Open
@mattruzicka

Description

@mattruzicka

In rails_admin version 3.1.2, when a model is configured to have tabbed scopes on the index page and you do a filter search, the results are always scoped to the first tab and not the current scope/tab as expected.

Reproduction steps

I updated the active_record dummy app Ball model to have scopes like this:

# frozen_string_literal: true

class Ball < ActiveRecord::Base
  has_one :comment, as: :commentable

  validates_presence_of :color, on: :create

  scope :red, -> { where(color: 'red') }
  scope :green, -> { where(color: 'green') }
  scope :blue, -> { where(color: 'blue') }

  def to_param
    color.present? ? color.downcase.tr(' ', '-') : id
  end

  rails_admin do
    list do
      scopes [:red, :green, :blue]
    end
  end
end

Here you can see that I'm on the "Blue" scope tab and added a filter to only show balls of type "Basketball".

Screenshot 2024-01-04 at 11 02 44 AM

After clicking refresh, I expect the page to stay on the "Blue" tab and show only basketballs, but instead, it updates to only show basketballs for the default scope which is "Red".

Screenshot 2024-01-04 at 11 02 54 AM

If I then click on the blue tab, I see the results that I expected, but having to do that is an extra step and breaks the expectations set by previous versions.

Additional context

  • rails version: 6.1.7.6
  • rails_admin version: 3.1.2

I'm updating from rails_admin version 2.2.1, so I know that scopes and filters behaved as expected in at least that version.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions