Class: Plain::ConversationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plain/conversations_controller.rb

Constant Summary collapse

PER_PAGE =
10

Instance Method Summary collapse

Instance Method Details

#allow_iframe_requestsObject



11
12
13
# File 'app/controllers/plain/conversations_controller.rb', line 11

def allow_iframe_requests
  response.headers.delete("X-Frame-Options")
end

#destroyObject



47
48
49
50
# File 'app/controllers/plain/conversations_controller.rb', line 47

def destroy
  @conversation = Plain::Conversation.find(params[:id])
  @conversation.destroy
end

#editObject



39
40
41
# File 'app/controllers/plain/conversations_controller.rb', line 39

def edit
  @conversation = Plain::Conversation.find(params[:id])
end

#indexObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/plain/conversations_controller.rb', line 15

def index
  @needs_back = true
  @conversations = Plain::Conversation.all

  if @conversations.empty?
    Plain::Conversation.create
  end

  @current_page = params[:page].to_i
  @next_page = @current_page + 1
  @conversations = Plain::Conversation.limit(PER_PAGE)
                               .offset(@current_page * PER_PAGE)
                               .order(pinned: :desc, pinned_at: :asc, created_at: :desc)
end

#newObject



34
35
36
37
# File 'app/controllers/plain/conversations_controller.rb', line 34

def new
  @conversation = Plain::Conversation.create
  redirect_to conversation_path(@conversation)
end

#pinObject



52
53
54
55
56
# File 'app/controllers/plain/conversations_controller.rb', line 52

def pin
  @conversation = Plain::Conversation.find(params[:id])
  new_state = !@conversation.pinned?
  @conversation.update(pinned: new_state, pinned_at: new_state ? Time.zone.now : nil )
end

#showObject



30
31
32
# File 'app/controllers/plain/conversations_controller.rb', line 30

def show
  @conversation = Plain::Conversation.find(params[:id])
end

#updateObject



43
44
45
# File 'app/controllers/plain/conversations_controller.rb', line 43

def update
  @conversation = Plain::Conversation.find(params[:id])
end