Class: Triumph::AchievementsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/triumph/achievements_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /achievements POST /achievements.xml



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/triumph/achievements_controller.rb', line 44

def create
  @achievement = Achievement.new(params[:triumph_achievement])
  @achievement.observe_class.downcase!

  if @achievement.save
    achievement_condition = AchievementCondition.new(params[:achievement_condition])
    achievement_condition.achievement_id = @achievement.id
    if achievement_condition.save
      redirect_to(@achievement, :notice => 'Achievement was successfully created.')
    else
      flash[:error] = "Failed to save achievement conditions"
    end
  else  
    render :action => "new"
  end
end

#destroyObject

DELETE /achievements/1 DELETE /achievements/1.xml



80
81
82
83
84
85
86
87
88
# File 'app/controllers/triumph/achievements_controller.rb', line 80

def destroy
  @achievement = Achievement.find(params[:id])
  @achievement.destroy

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

#editObject

GET /achievements/1/edit



38
39
40
# File 'app/controllers/triumph/achievements_controller.rb', line 38

def edit
  @achievement = Achievement.find(params[:id])
end

#indexObject

GET /achievements GET /achievements.xml



5
6
7
8
9
10
11
12
# File 'app/controllers/triumph/achievements_controller.rb', line 5

def index
  @achievements = Achievement.all

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

#newObject

GET /achievements/new GET /achievements/new.xml



28
29
30
31
32
33
34
35
# File 'app/controllers/triumph/achievements_controller.rb', line 28

def new
  @achievement = Achievement.new

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

#showObject

GET /achievements/1 GET /achievements/1.xml



16
17
18
19
20
21
22
23
24
# File 'app/controllers/triumph/achievements_controller.rb', line 16

def show
  @achievement = Achievement.find(params[:id])
  @conditions = @achievement.achievement_conditions

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

#updateObject

PUT /achievements/1 PUT /achievements/1.xml



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/triumph/achievements_controller.rb', line 63

def update
  @achievement = Achievement.find(params[:id])
  @achievement.observe_class.downcase!
  
  respond_to do |format|
    if @achievement.update_attributes(params[:triumph_achievement])
      format.html { redirect_to(@achievement, :notice => 'Achievement was successfully updated.') }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @achievement.errors, :status => :unprocessable_entity }
    end
  end
end