Class: Admin::ProgramsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/programs_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) create

Create a reg



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/admin/programs_controller.rb', line 47

def create
  source_document = params[:program].delete("source_document")
  source_website = params[:program].delete("source_website")
  @program = Program.new(params[:program])

  # A couple of attached docs
  @program.source_document = Document.new(source_document) if source_document && !source_document['link'].blank?
  @program.source_website = Document.new(source_website) if source_website && !source_document['link'].blank?

  respond_to do |format|
    if @program.save
      format.html { redirect_to(edit_program_path(@program), :notice => 'Program was successfully created.') }
      format.xml  { render :xml => @program, :status => :created, :location => @program }
    else
      flash.now[:error] = "Could not create."
      format.html { render :action => "new" }
      format.xml  { render :xml => @program.errors, :status => :unprocessable_entity }
    end
  end
end

- (Object) destroy

Delete a reg



98
99
100
101
102
103
104
105
106
# File 'app/controllers/admin/programs_controller.rb', line 98

def destroy
  @program = Program.find(params[:id])
  @program.destroy

  respond_to do |format|
    format.html { redirect_to(programs_url) }
    format.xml  { head :ok }
  end
end

- (Object) edit

Edit reg form



42
43
44
# File 'app/controllers/admin/programs_controller.rb', line 42

def edit
  @program = Program.find(params[:id])
end

- (Object) index

List Programs



12
13
14
15
16
17
18
19
# File 'app/controllers/admin/programs_controller.rb', line 12

def index
  @programs = Program.all

  respond_to do |format|
    format.html
    format.xml  { render :xml => @programs }
  end
end

- (Object) new

New reg form



32
33
34
35
36
37
38
39
# File 'app/controllers/admin/programs_controller.rb', line 32

def new
  @program = Program.new

  respond_to do |format|
    format.html
    format.xml  { render :xml => @program }
  end
end

- (Object) show

Show reg



22
23
24
25
26
27
28
29
# File 'app/controllers/admin/programs_controller.rb', line 22

def show
  @program = Program.find(params[:id])

  respond_to do |format|
    format.html
    format.xml  { render :xml => @program }
  end
end

- (Object) slug

Slug for AJAX



5
6
7
8
9
# File 'app/controllers/admin/programs_controller.rb', line 5

def slug
  respond_to do |format|
    format.js  { render :json => [Program.find(params[:id]).slug]  }
  end
end

- (Object) update

Update a reg



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/admin/programs_controller.rb', line 69

def update
  @program = Program.find(params[:id])

  @program.source_document ||= Document.create
  @program.source_website ||= Document.create

  # Accumulate results
  results = []
  results << @program.source_document.update_attributes(params[:program].delete("source_document") || {})
  results << @program.source_website.update_attributes(params[:program].delete("source_website") || {})

  # Save if doc updated
  @program.save if @program.changed?

  results << @program.update_attributes(params[:program])

  respond_to do |format|
    if results.all?
      format.html { redirect_to(edit_program_path(@program), :notice => 'Program was successfully updated.') }
      format.xml  { head :ok }
    else
      flash.now[:error] = "Could not update."
      format.html { render :action => "edit" }
      format.xml  { render :xml => @program.errors, :status => :unprocessable_entity }
    end
  end
end