Class: Flyboy::GoalsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#closeObject



91
92
93
94
95
96
97
98
99
# File 'app/controllers/flyboy/goals_controller.rb', line 91

def close
  if @goal.close!
    flash[:success] = t("messages.goals.close_ok")
  else
    flash[:danger] = t("messages.goals.close_error")
  end

  redirect_to goals_path
end

#createObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/flyboy/goals_controller.rb', line 41

def create
  @goal ||= Goal.new(goal_params)

  authorize! :create, @goal

  if @goal.save
    flash[:success] = t("messages.goals.create_ok")
    redirect_to @goal
  else
    render :new
  end
end

#destroyObject



74
75
76
77
78
79
# File 'app/controllers/flyboy/goals_controller.rb', line 74

def destroy
  authorize! :delete, @goal

  @goal.destroy
  redirect_to goals_path
end

#editObject



54
55
56
# File 'app/controllers/flyboy/goals_controller.rb', line 54

def edit
  authorize! :update, @goal
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/flyboy/goals_controller.rb', line 10

def index
  authorize! :list, Goal

  @goals ||= Goal.all

  @order ||= sortable_column_order do |column, direction|
    case column
    when "title"
      %(LOWER(flyboy_goals.#{column}) #{direction})
    else
      params["sort"] = "status"
      "status ASC"
    end
  end

  @filters ||= SmallData::FilterForGoals.new(cookies)

  @goals = @goals.order(@order)
  @goals = @filters.apply @goals
end

#newObject



35
36
37
38
39
# File 'app/controllers/flyboy/goals_controller.rb', line 35

def new
  @goal ||= Goal.new

  authorize! :create, @goal
end

#openObject



81
82
83
84
85
86
87
88
89
# File 'app/controllers/flyboy/goals_controller.rb', line 81

def open
  if @goal.open!
    flash[:success] = t("messages.goals.open_ok")
  else
    flash[:danger] = t("messages.goals.open_error")
  end

  redirect_to @goal
end

#showObject



31
32
33
# File 'app/controllers/flyboy/goals_controller.rb', line 31

def show
  authorize! :read, @goal
end

#updateObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/flyboy/goals_controller.rb', line 58

def update
  authorize! :update, @goal

  if @goal.update_attributes(goal_params)
    flash[:success] = t("messages.goals.update_ok")

    if @goal.closed?
      redirect_to goals_path
    else
      redirect_to @goal
    end
  else
    render :edit
  end
end