Skip to content

Instantly share code, notes, and snippets.

@pama
Last active March 16, 2022 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pama/fe20a1a883c00baa1a80abb185aaff3a to your computer and use it in GitHub Desktop.
Save pama/fe20a1a883c00baa1a80abb185aaff3a to your computer and use it in GitHub Desktop.
Search model example
class Cligest::DocumentsController < ApplicationController
# ...
def index
@document_search = DocumentSearch.new(document_search_params)
@documents = @document_search.perform
# perhaps a few more initializations
respond_to do |format|
format.html {}
format.js {}
end
end
# ...
private
def document_search_params
end
end
class DocumentSearch
include ActiveModel::Model
include ActiveModel::Conversion
extend ActiveModel::Naming
include ActiveModel::Attributes
include ActiveModel::AttributeMethods
include ActiveModel::Validations
#include ActiveModel::AttributeAssignment
include ActiveRecord::AttributeAssignment
attribute :starts_at, :datetime
attribute :ends_at, :datetime
attribute :text, :string
attribute :tag_ids, :string
attribute :catalog_ids, :string
# returns a Document search by provided attributes
def perform
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment