How do I search Action Text with Ransack?
I have set up a basic search using Ransack but I don't understand how to get it to search Action Text. This is how it is implimented in the search_form_for:
The rcontent is the Action Text portion.
For anyone else searching for this issue, I found a solution.
Add this to your model -
And then add or_action_text_rich_text_body to your search field, because "body" is what is created when the ActionText migration is created.
Thank you! I am now getting duplicates in my searches though. Did that happen to you?
Let's say you have an ActionText field like so:
You can join that without defining another association like so:
One option could be to do a full text search in PostgreSQL:
joins(:rich_text_body).where("to_tsvector(action_text_rich_texts.body) @@ websearch_to_tsquery('english', ?)", phrase)
One of the reasons I went with this approach was to help make the HTML-formatted text a bit easier to search through, and give the user a bit more flexibility. For example, since I used the
websearch_to_tsquery, it supports things like quoting to search for a phrase, etc.
EDIT Heh just noticed this is a rather old thread. Anyway, maybe this will help someone in the future!