diff --git a/Gemfile b/Gemfile index d9210694..c1a8d474 100644 --- a/Gemfile +++ b/Gemfile @@ -39,7 +39,7 @@ gem "administrate", "~> 0.18.0" # Translatable content gem "mobility", "~> 1.2" -gem "mobility-ransack", "~> 1.2" +gem "mobility-ransack", "~> 1.2.2" # Soft deletions gem "discard", "~> 1.2" diff --git a/Gemfile.lock b/Gemfile.lock index db594d08..22b9975d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -479,7 +479,7 @@ DEPENDENCIES jsbundling-rails (~> 1.0) kaminari (~> 1.2) mobility (~> 1.2) - mobility-ransack (~> 1.2) + mobility-ransack (~> 1.2.2) pg (~> 1.1) puma (~> 6.4) pundit (~> 2.2) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 75d4acfb..d65d7342 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -6,7 +6,7 @@ class StoriesController < ApplicationController def index # Fields to search for - @search_fields = :title_or_description_or_outcomes_or_source_or_story_updates_title_i_cont_any + @search_fields = :title_or_description_or_outcomes_or_source_or_story_updates_title_or_story_updates_description_i_cont_any # Inspired from https://github.com/activerecord-hackery/ransack/issues/218#issuecomment-16504630 # Make sure multiple words are split and searched diff --git a/app/models/story.rb b/app/models/story.rb index ca199eec..891f8f3b 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -30,6 +30,14 @@ class Story < ApplicationRecord discussions.undiscard_all end + def self.ransackable_attributes(auth_object = nil) + %w[title description outcomes source country] + end + + def self.ransackable_associations(auth_object = nil) + %w[story_updates] + end + # https://github.com/countries/country_select#getting-the-country-name-from-the-countries-gem # Assuming country_select is used with User attribute `country` # This will attempt to translate the country name and use the default diff --git a/app/models/story_update.rb b/app/models/story_update.rb index 1c11e5a8..c9458d5c 100644 --- a/app/models/story_update.rb +++ b/app/models/story_update.rb @@ -9,4 +9,12 @@ class StoryUpdate < ApplicationRecord validates :title, :description, presence: true translates :title, :description + + def self.ransackable_attributes(auth_object = nil) + %w[title description] + end + + def self.ransackable_associations(auth_object = nil) + %w[story] + end end