Files
danbooru/app/models/wiki_page_version.rb
evazion 216d735f24 Fix #3696: API: handle boolean params consistently
* Use ApplicationRecord#attribute_matches to handle boolean attributes
  consistently in search methods.

* Add support for searching various boolean attributes that previously
  weren't supported.
2018-05-03 19:57:14 -05:00

44 lines
892 B
Ruby

class WikiPageVersion < ApplicationRecord
belongs_to :wiki_page
belongs_to_updater
belongs_to :artist, optional: true
delegate :visible?, :to => :wiki_page
module SearchMethods
def for_user(user_id)
where("updater_id = ?", user_id)
end
def search(params)
q = super
if params[:updater_id].present?
q = q.for_user(params[:updater_id].to_i)
end
if params[:wiki_page_id].present?
q = q.where("wiki_page_id = ?", params[:wiki_page_id].to_i)
end
q = q.attribute_matches(:is_locked, params[:is_locked])
q = q.attribute_matches(:is_deleted, params[:is_deleted])
q.apply_default_order(params)
end
end
extend SearchMethods
def pretty_title
title.tr("_", " ")
end
def category_name
Tag.category_for(title)
end
def other_names_array
other_names.to_s.scan(/\S+/)
end
end