ransack
ransack copied to clipboard
Can text in ActionText be searched?
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?
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.
We should support this as ActionText is a core Rails component.
Any update? This should be high priority.
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.
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.
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!
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
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
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