Class: SolidStackWeb::CableMessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solid_stack_web/cable_messages_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::PERIOD_DURATIONS

Instance Method Summary collapse

Instance Method Details

#indexObject



3
4
5
6
7
8
9
10
11
# File 'app/controllers/solid_stack_web/cable_messages_controller.rb', line 3

def index
  @search = params[:q].presence
  scope   = ::SolidCable::Message.where(channel_hash: params[:channel_hash])
  if @search
    scope = scope.where("payload LIKE ?", "%#{::ActiveRecord::Base.sanitize_sql_like(@search)}%")
  end
  @channel_name    = ::SolidCable::Message.where(channel_hash: params[:channel_hash]).pick(:channel) || params[:channel_hash]
  @pagy, @messages = pagy(scope.order(created_at: :desc))
end