Class: Chatty::ChatsController

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

Instance Method Summary collapse

Instance Method Details

#closeObject



60
61
62
63
64
# File 'app/controllers/chatty/chats_controller.rb', line 60

def close
  @chat.close
  @chat.create_activity :key => "chatty/chat.closed", :owner => current_user
  redirect_to chat_path(@chat)
end

#createObject



26
27
28
29
30
31
32
33
34
# File 'app/controllers/chatty/chats_controller.rb', line 26

def create
  @chat = Chatty::Chat.new(chat_params)

  if @chat.save
    redirect_to @chat, notice: 'Chat was successfully created.'
  else
    render action: 'new'
  end
end

#destroyObject



44
45
46
47
# File 'app/controllers/chatty/chats_controller.rb', line 44

def destroy
  @chat.destroy
  redirect_to chats_url, notice: 'Chat was successfully destroyed.'
end

#editObject



23
24
# File 'app/controllers/chatty/chats_controller.rb', line 23

def edit
end

#handleObject



54
55
56
57
58
# File 'app/controllers/chatty/chats_controller.rb', line 54

def handle
  @chat.handle!
  @chat.create_activity :key => "chatty/chat.handled", :owner => current_user
  redirect_to chat_path(@chat)
end

#indexObject



6
7
8
9
10
# File 'app/controllers/chatty/chats_controller.rb', line 6

def index
  @ransack_params = params[:q] || {}
  @ransack = Chatty::Chat.ransack(@ransack_params.clone)
  @chats = @ransack.result.order(:id).reverse_order
end

#messagesObject



49
50
51
52
# File 'app/controllers/chatty/chats_controller.rb', line 49

def messages
  @messages = @chat.messages
  render :partial => "messages", :layout => false
end

#newObject



19
20
21
# File 'app/controllers/chatty/chats_controller.rb', line 19

def new
  @chat = Chatty::Chat.new
end

#showObject



12
13
14
15
16
17
# File 'app/controllers/chatty/chats_controller.rb', line 12

def show
  respond_to do |format|
    format.json { render(:json => {:chat => @chat.json}) }
    format.html { render :show }
  end
end

#updateObject



36
37
38
39
40
41
42
# File 'app/controllers/chatty/chats_controller.rb', line 36

def update
  if @chat.update(chat_params)
    redirect_to @chat, notice: 'Chat was successfully updated.'
  else
    render action: 'edit'
  end
end