app/controllers/flyboy/goals_controller.rb in flyboy-0.0.2 vs app/controllers/flyboy/goals_controller.rb in flyboy-0.0.3
- old
+ new
@@ -6,28 +6,42 @@
before_action :set_objects,
only: [:show, :edit, :update, :destroy, :open, :close]
def index
- authorize! :read, Goal
+ authorize! :list, Goal
- @filters = SmallData::FilterForGoals.new(cookies)
- @goals = @filters.apply get_index_goals
+ @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
def show
authorize! :read, @goal
end
def new
- @goal = Goal.new
+ @goal ||= Goal.new
authorize! :create, @goal
end
def create
- @goal = Goal.new(goal_params)
+ @goal ||= Goal.new(goal_params)
authorize! :create, @goal
if @goal.save
flash[:success] = t("messages.goals.create_ok")
@@ -94,25 +108,9 @@
[:title, :description]
end
def goal_params
params.require(:goal).permit(permitted_params)
- end
-
- def get_index_goals
- Goal.all.order(get_index_order)
- end
-
- def get_index_order
- sortable_column_order do |column, direction|
- case column
- when "title"
- %(LOWER(flyboy_goals.#{column}) #{direction})
- else
- params["sort"] = "status"
- "status ASC"
- end
- end
end
end
end