Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic ransack configuration for table backend #35

Open
mpapis opened this issue Apr 9, 2024 · 0 comments
Open

Automatic ransack configuration for table backend #35

mpapis opened this issue Apr 9, 2024 · 0 comments

Comments

@mpapis
Copy link

mpapis commented Apr 9, 2024

I'm using rails with activeadmin, I want to be able to filter using all translations:

filter :translations_title_i_cont, as: :string, label: 'Title Search'

To make it work I've had to make a bit of magic in application_record.rb:

class ApplicationRecord < ActiveRecord::Base
  extend Mobility

  self.abstract_class = true

  class << self
    alias mobility_translates translates

    def translates(*attributes, **options)
      mobility_translates(*attributes, **options)
      translation_class = const_get(:Translation)
      translation_class.define_singleton_method(:ransackable_attributes) do |_arg = nil|
        attributes.map(&:to_s)
      end
      translation_class.define_singleton_method(:ransackable_associations) do |_arg = nil|
        []
      end
    end
  end
end

Would it be possible for this gem to define those two methods automatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant