active admin filter on show page

601 views Asked by At

My app has 3 models that I am concerned with:

Page:

class Page < ActiveRecord::Base
  has_many :page_translations
  has_many :translations, through: :page_translations, :class_name => Translation.name

  accepts_nested_attributes_for :page_translations, :allow_destroy => true
end

PageTranslation:

class PageTranslation < ActiveRecord::Base
  belongs_to :page
  belongs_to :translation

end

and Translation:

class Translation < ActiveRecord::Base
  validates_presence_of :locale, :key
  has_many :pages, through: :page_translations
  has_many :page_translations

  accepts_nested_attributes_for :page_translations, :allow_destroy => true
end

When a user visits the pages index they are provided with a link to the show action for that page.

index do
    column :slug do |page|
      link_to(page.slug, admin_page_path(page))
    end
  end

On the show page I have a list of all of the translations that are associated with that page:

show title: :slug do |page|
    panel "Translations" do
      table_for(page.translations, sortable: true) do
        column :value do |translation|
          link_to(translation.value, edit_admin_translation_path(translation))
        end.join(', ').html_safe
        column :key
        column :locale
      end
    end
  end

On the show action for the page model I would like to add a filter so that the user can sort by locale or value. I am very new to active admin(As I am sure you can tell from my smelly code) and I have been wrestling with this problem for some time. Any help is greatly appreciated.

0

There are 0 answers