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



95
96
97
98
99
100
101
102
103
# File 'app/controllers/flyboy/goals_controller.rb', line 95

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



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/flyboy/goals_controller.rb', line 45

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



78
79
80
81
82
83
# File 'app/controllers/flyboy/goals_controller.rb', line 78

def destroy
  authorize! :delete, @goal

  @goal.destroy
  redirect_to goals_path
end

#editObject



58
59
60
# File 'app/controllers/flyboy/goals_controller.rb', line 58

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
30
31
32
33
# 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", "status"
      %(LOWER(flyboy_goals.#{column}) #{direction})
    when "progress"
      %(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)
  @goals = @goals.search(params[:q])
  @goals = @goals.page(params[:page])
end

#newObject



39
40
41
42
43
# File 'app/controllers/flyboy/goals_controller.rb', line 39

def new
  @goal ||= Goal.new

  authorize! :create, @goal
end

#openObject



85
86
87
88
89
90
91
92
93
# File 'app/controllers/flyboy/goals_controller.rb', line 85

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



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

def show
  authorize! :read, @goal
end

#updateObject



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

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