Class: PageAttachmentsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Instance Method Details

#createObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/page_attachments_controller.rb', line 22

def create
  @pa = PageAttachment.new params[:page_attachment]
  @pa.user_id = current_user.id

  if @pa.page.editable?(current_user)
    respond_to do |format|
      if @pa.page_attachment.present? && @pa.save
        format.html { redirect_to @pa.page }
      else
        flash[:error] = 'Could not upload your file.'
        format.html { redirect_to @pa.page }
      end
    end
  else
    flash[:error] = "You don't have permission to do that."
    redirect_to @pa.page
  end
end

#destroyObject


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/page_attachments_controller.rb', line 41

def destroy
  @pa = PageAttachment.find(params[:id])

  if @pa.page.editable?(current_user)
    @pa.destroy
    flash[:notice] = "Page attachment successfully deleted."

    respond_to do |format|
      format.html { redirect_to @pa.page }
    end
  else
    flash[:error] = "You don't have permission to do that."
    redirect_to @pa.page
  end
end

#repositionObject


57
58
59
60
61
# File 'app/controllers/page_attachments_controller.rb', line 57

def reposition
  order = params[:page_attachment]
  PageAttachment.reposition(order)
  render :text => order.inspect
end

#updateObject


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/page_attachments_controller.rb', line 2

def update
  @pa = PageAttachment.find(params[:id])
  @pa.user_id = current_user.id

  if @pa.page.editable?(current_user)
    respond_to do |format|
      if @pa.update_attributes(params[:page_attachment])
        format.html { redirect_to @pa.page }
      else
        flash[:error] = 'Could not upload your file.'
        format.html { redirect_to @pa.page }
      end
    end
  else
    flash[:error] = "You don't have permission to do that."
    redirect_to @pa.page
  end

end