Class: PreconditionsController

Inherits:
ApplicationController show all
Defined in:
lib/branston/app/controllers/preconditions_controller.rb

Overview

This file is part of Branston.

Branston is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation.

Branston is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Branston.  If not, see <http://www.gnu.org/licenses/>.

Instance Method Summary collapse

Instance Method Details

#createObject

POST /preconditions POST /preconditions.xml



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/branston/app/controllers/preconditions_controller.rb', line 66

def create
  @precondition = Precondition.new(params[:precondition])
  @precondition.scenario = @scenario
  @preconditions = @scenario.preconditions
  respond_to do |format|
    if @precondition.save
      flash[:notice] = 'Precondition was successfully created.'
      format.html { redirect_to(@precondition) }
      format.xml  { render :xml => @precondition, :status => :created, :location => @precondition }
      format.js
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @precondition.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /preconditions/1 DELETE /preconditions/1.xml



102
103
104
105
106
107
108
109
110
111
# File 'lib/branston/app/controllers/preconditions_controller.rb', line 102

def destroy
  @precondition = Precondition.find(params[:id])
  @precondition.destroy

  respond_to do |format|
    format.html { redirect_to(preconditions_url(:scenario_id => @precondition.scenario_id)) }
    format.xml  { head :ok }
    format.js
  end
end

#editObject

GET /preconditions/1/edit



60
61
62
# File 'lib/branston/app/controllers/preconditions_controller.rb', line 60

def edit
  @precondition = Precondition.find(params[:id])
end

#indexObject

GET /preconditions GET /preconditions.xml



25
26
27
28
29
30
31
32
33
# File 'lib/branston/app/controllers/preconditions_controller.rb', line 25

def index
  @preconditions = @scenario.preconditions

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @preconditions }
    format.js
  end
end

#newObject

GET /preconditions/new GET /preconditions/new.xml



48
49
50
51
52
53
54
55
56
57
# File 'lib/branston/app/controllers/preconditions_controller.rb', line 48

def new
  @precondition = Precondition.new
  @preconditions = @scenario.preconditions
  @preconditions.push @precondition
  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @precondition }
    format.js
  end
end

#showObject

GET /preconditions/1 GET /preconditions/1.xml



37
38
39
40
41
42
43
44
# File 'lib/branston/app/controllers/preconditions_controller.rb', line 37

def show
  @precondition = Precondition.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @precondition }
  end
end

#updateObject

PUT /preconditions/1 PUT /preconditions/1.xml



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/branston/app/controllers/preconditions_controller.rb', line 85

def update
  @precondition = Precondition.find(params[:id])

  respond_to do |format|
    if @precondition.update_attributes(params[:precondition])
      flash[:notice] = 'Precondition was successfully updated.'
      format.html { redirect_to(@precondition) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @precondition.errors, :status => :unprocessable_entity }
    end
  end
end