Class: PagesController

Inherits:
InheritedResources::Base
  • Object
show all
Defined in:
app/controllers/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#authorize_resource!Object



13
14
15
# File 'app/controllers/pages_controller.rb', line 13

def authorize_resource!
  authorize! params[:action].to_sym, resource
end

#can_access_resources?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/controllers/pages_controller.rb', line 78

def can_access_resources?
  current_ability.can?(params[:action].to_sym, resource) && current_ability.can?(params[:action].to_sym, @sitemap)
end

#createObject



52
53
54
# File 'app/controllers/pages_controller.rb', line 52

def create
  create! { (@parent_page ? page_child_path(@parent_page, @page) : @page) }
end

#editObject



45
46
47
48
49
50
# File 'app/controllers/pages_controller.rb', line 45

def edit
  edit! do |format|
    @attachment = Attachment.new(:page=>@page)
    @s3provider = S3Provider.new(:key=>"attachments/#{current_user.id}")
  end
end

#maybe_authenticateObject



72
73
74
75
76
# File 'app/controllers/pages_controller.rb', line 72

def maybe_authenticate
  unless user_signed_in?
    authenticate_user! unless current_ability.can?(:read, resource) && current_ability.can?(:read, @sitemap)
  end
end

#resourceObject



67
68
69
70
# File 'app/controllers/pages_controller.rb', line 67

def resource
  return @page ||= Page.find(params[:id])
  @attachments = @page.attachments
end

#showObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/pages_controller.rb', line 17

def show
  @sidebar = true
  if params[:id]
    @sitemap ||= resource.sitemaps.sort{|t,u| t.url.size <=> u.url.size}[0]
    @page = resource
  else
    @sitemap = Sitemap.from_request_params(params)
    @page = @sitemap.try(:resource)
  end
  if @page
    @child_pages = Sitemap.accessible_by(current_ability).where(:parent_id=>@sitemap.id)

    if can_access_resources?
      respond_with @page, @sitemap, @child_pages, @attachments
    else
      if user_signed_in?
        flash[:notice] = "How did you find that page?  Please contact your administrator if you believe you should have access to that resource."
        redirect_to root_url
      else
        authenticate_user!
      end
    end
  else
    flash[:notice] = "Sorry, we couldn't find the resource you were looking for!"
    redirect_to root_url
  end
end

#updateObject



56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/pages_controller.rb', line 56

def update
  update! do |format|
    if params[:child_id]
      @parent_page = @page
      @page = Page.find(params[:child_id])
      @page.parent = @parent_page
      @page.save
    end
  end
end