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



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

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

#can_access_resources?Boolean

Returns:

  • (Boolean)


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

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

#createObject



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

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

#editObject



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

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

#maybe_authenticateObject



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

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

#resourceObject



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

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

#showObject



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
44
# File 'app/controllers/pages_controller.rb', line 18

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



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

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