Class: Chatty::MessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/chatty/messages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/chatty/messages_controller.rb', line 7

def create
  spawn_message
  
  if @message.save
    render :json => {
      :success => true
    }
  else
    render :json => {
      :success => false,
      :errors => @message.errors.full_messages.join(". ")
    }
  end
end

#indexObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/chatty/messages_controller.rb', line 22

def index
  @ransack_params = params[:q] || {}
  @ransack = Chatty::Message.ransack(@ransack_params)
  @messages = @ransack.result.order(:created_at, :id)
  
  respond_to do |format|
    format.json { render(:json => {:messages => messages_json(@messages)}) }
  end
end

#newObject



2
3
4
5
# File 'app/controllers/chatty/messages_controller.rb', line 2

def new
  spawn_message
  render :new, :layout => false
end