#encoding: utf-8 module Flyboy class GoalsController < ::Flyboy::ApplicationController handles_sortable_columns before_action :set_objects, only: [:show, :edit, :update, :destroy, :open, :close] def index authorize! :read, Goal @filters = SmallData::FilterForGoals.new(cookies) @goals = @filters.apply get_index_goals end def show authorize! :read, @goal end def new @goal = Goal.new authorize! :create, @goal end 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 def edit authorize! :update, @goal end 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 def destroy authorize! :delete, @goal @goal.destroy redirect_to goals_path end def open if @goal.open! flash[:success] = t("messages.goals.open_ok") else findlash[:danger] = t("messages.goals.open_error") end redirect_to @goal end 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 private def set_objects @goal = Goal.find(params[:id]) end def permitted_params [: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