Class: Event
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Event
- Defined in:
- app/models/event.rb
Overview
Instance Attribute Summary collapse
-
#created_at ⇒ DateTime
When the record was created.
-
#happenings_count ⇒ Integer
Counter cache for Happening.
-
#id ⇒ Integer
Unique identifier for Event.
-
#pinned ⇒ Boolean
- true
-
if this Event has priority.
-
#start_on ⇒ date
When start Event.
-
#stop_on ⇒ date
When end Event.
-
#tickets_frequency ⇒ String
Enum of tickets frequency statuses.
-
#title ⇒ String
Title of Event.
-
#updated_at ⇒ DateTime
When the record was updated.
-
#where ⇒ string
Where the Event is located.
Class Method Summary collapse
-
.searchable(from: nil, to: nil, group_id: nil, text: nil, editor: false) ⇒ Object
Search event with params.
Instance Method Summary collapse
-
#image_url(_variant = :card) ⇒ String
Image path with variand or default image.
Instance Attribute Details
#created_at ⇒ DateTime
Returns when the record was created.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
#happenings_count ⇒ Integer
Returns counter cache for Happening.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
#id ⇒ Integer
Returns unique identifier for Event.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
#pinned ⇒ Boolean
Returns [true] if this Event has priority.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
#start_on ⇒ date
Returns when start Event.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
#stop_on ⇒ date
Returns when end Event.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
#tickets_frequency ⇒ String
Returns enum of tickets frequency statuses.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
#title ⇒ String
Returns title of Event.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
#updated_at ⇒ DateTime
Returns when the record was updated.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
#where ⇒ string
Returns where the Event is located.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
Class Method Details
.searchable(from: nil, to: nil, group_id: nil, text: nil, editor: false) ⇒ Object
Search event with params
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/event.rb', line 38 class Event < ApplicationRecord has_rich_text :body has_one_attached :image do |attachable| attachable.variant :card, resize_to_limit: [ 417, 278 ] attachable.variant :aside, resize_to_limit: [ 318, 318 ] attachable.variant :ticket, resize_to_limit: [ 150, 68 ] end belongs_to :group has_many :happenings, dependent: :destroy has_many :tickets, through: :happenings validates :title, presence: true enum :tickets_frequency, %i[any single daily weekly monthly] scope :searchable, ->(from: nil, to: nil, group_id: nil, text: nil, editor: false, reserved: false) do from = Time.zone.now unless editor || from.present? by_keys = {} by_keys[:stop_on] = (from.try(:to_date)..) if from.present? by_keys[:start_on] = (..to.try(:to_date)) if to.present? by_keys[:group_id] = group_id if group_id.present? by_keys[:reserved] = false unless reserved by_text = text.present? ? [ "title ilike :text", { text: "%#{text}%" } ] : nil where(by_text).where(by_keys) end # @return {String} image path with variand or default image def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end end |
Instance Method Details
#image_url(_variant = :card) ⇒ String
Returns image path with variand or default image.
63 64 65 |
# File 'app/models/event.rb', line 63 def image_url(_variant = :card) image.present? ? image.variant(:card) : "default.png" end |