Last active
March 16, 2022 12:20
-
-
Save pama/fe20a1a883c00baa1a80abb185aaff3a to your computer and use it in GitHub Desktop.
Search model example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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