ransack icon indicating copy to clipboard operation
ransack copied to clipboard

Can text in ActionText be searched?

Open MtnBiker opened this issue 2 years ago • 9 comments

Can text in ActionText be searched?

Update: https://thoughtbot.com/blog/full-text-search-with-postgres-and-action-text has a work around for Postgres, but it would be nice if Ransack could handle it. Or maybe it can?

MtnBiker avatar Aug 26 '21 02:08 MtnBiker

Subscribing this issue for any update.

Meanwhile, I am using extra column in parent model of ActionText (to store plain text) and use the column for Ransack search. Thanks @MtnBiker for the link.

twnaing avatar Oct 11 '21 09:10 twnaing

We should support this as ActionText is a core Rails component.

scarroll32 avatar May 19 '22 12:05 scarroll32

Any update? This should be high priority.

istvan-ujjmeszaros avatar Jun 11 '22 01:06 istvan-ujjmeszaros

Did I read that a replacement for Twix was being considered? And would that have an impact on Action Text.

I, too, set up a plain text column.

MtnBiker avatar Jun 11 '22 03:06 MtnBiker

Any update? This should be high priority.

@istvan-ujjmeszaros the Ransack team are volunteers, and we all have jobs, families etc. and limited time. If you want this feature please try to submit a PR ... we can also work with you if you are not 100% sure how to approach it.

Even a PR with just some tests would be a good start, and perhaps someone else would pick it up.

scarroll32 avatar Jun 11 '22 08:06 scarroll32

Did I read that a replacement for Twix was being considered? And would that have an impact on Action Text.

I, too, set up a plain text column.

I've not heard that one, but I am huge Twix fan!

twix

scarroll32 avatar Jun 11 '22 08:06 scarroll32

Hi, this is an old one...

I've been doing query with Ransack on action_text (rich_text) like this :

class MyModel < ApplicationRecord

  has_rich_text :description

  # Used to query the ActionText directly
  has_one :action_text_rich_text,
    class_name: 'ActionText::RichText',
    as: :record

   (...)
end

View:

= f.search_field :action_text_rich_text_body_cont

This will work up to Ransack version 3.2.1.

With the new release v4.0.0 we need to explicitly add ransackable_attributes method to model ActionText::RichText. I am still trying to figure out how I can do this, if someone has an idea ?

[edit]

Here is my working solution for now to add Ransack mandatory methods to RichText.

Please note this code basically revert back Ransack to the old behaviour which allows all attributes and associations which have been found dangerous. I my case it's only used with private applications.

https://gist.github.com/pasl/01ce2c65565753399fd3a7771a15364f

pasl avatar Feb 09 '23 20:02 pasl

  ActionText::RichText.class_eval do
    def self.ransackable_attributes(*)
      ['body']
    end
  end
class MyModel
  has_rich_text :description

  def ransackable_associations(*)
    ['rich_text_description']
  end
end

Then

= f.search_field :rich_text_description_body_cont

should just work with Ransack 4.0.0

MaksJS avatar Feb 28 '23 10:02 MaksJS

From StackOverflow answer:

# config/initializers/action_text.rb

ActiveSupport.on_load(:action_text_rich_text) do
  class ActionText::RichText < ActionText::Record
    def self.ransackable_attributes(auth_object = nil)
      authorizable_ransackable_attributes
    end
  end
end

mechnicov avatar Sep 12 '23 15:09 mechnicov