Class: SponsoredProjectsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Instance Method Details

#archiveObject


52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/sponsored_projects_controller.rb', line 52

def archive
  authorize! :archive, SponsoredProject
  @project = SponsoredProject.find(params[:id])
  if @project.update_attributes({:is_archived => true})
    flash[:notice] = 'Project was successfully archived.'
    redirect_to(sponsored_projects_path)
  else
    flash[:notice] = 'Project could not be archived.'
    redirect_to(sponsored_projects_path)
  end
end

#createObject


26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/sponsored_projects_controller.rb', line 26

def create
  authorize! :create, SponsoredProject
  @project = SponsoredProject.new(params[:sponsored_project])
  @sponsors = SponsoredProjectSponsor.current

  if @project.save
    flash[:notice] = 'Project was successfully created.'
    redirect_back_or_default(sponsored_projects_path)
  else
    render "new"
  end
end

#editObject


20
21
22
23
24
# File 'app/controllers/sponsored_projects_controller.rb', line 20

def edit
  authorize! :update, SponsoredProject
  @project = SponsoredProject.find(params[:id])
  @sponsors = SponsoredProjectSponsor.current
end

#indexObject


7
8
9
10
11
# File 'app/controllers/sponsored_projects_controller.rb', line 7

def index
  authorize! :read, SponsoredProject
  @projects = SponsoredProject.current
  @sponsors = SponsoredProjectSponsor.current
end

#newObject


13
14
15
16
17
18
# File 'app/controllers/sponsored_projects_controller.rb', line 13

def new
  authorize! :create, SponsoredProject
  store_previous_location
  @project = SponsoredProject.new
  @sponsors = SponsoredProjectSponsor.current
end

#updateObject


39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/sponsored_projects_controller.rb', line 39

def update
  authorize! :update, SponsoredProject
  @project = SponsoredProject.find(params[:id])
  @sponsors = SponsoredProjectSponsor.current

  if @project.update_attributes(params[:sponsored_project])
    flash[:notice] = 'Project was successfully updated.'
    redirect_to(sponsored_projects_path)
  else
    render "edit"
  end
end