All threads / How do I search Action Text with Ransack?

Ask A Question


You’re not receiving notifications from this thread.

How do I search Action Text with Ransack?

Ryan Carter asked in Rails

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:

f.search_field :title_or_rcontent_or_city_or_state_i_cont

The rcontent is the Action Text portion.

For anyone else searching for this issue, I found a solution.

Add this to your model -
has_one :action_text_rich_text,
class_name: 'ActionText::RichText',
as: :record

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.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.