Files
grecia/app/controllers/admin/budget_investment_milestones_controller.rb
iagirre 471c9730cc Refactorings
- Cleanup Translatable module (`translation_params` method too large)
- Move globalize_helpers partial to admin folder
- Use any class for method translation_params
- Helpers in `GlobalizeHelpers` make sure all are in use and see if they can be more legible
- Review js name clases and methods see if they can be more legible
- Refactor milestone views into partials with nice spacing between attributes
2018-05-09 16:58:47 +02:00

75 lines
2.0 KiB
Ruby

class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
include Translatable
before_action :load_budget_investment, only: [:index, :new, :create, :edit, :update, :destroy]
before_action :load_budget_investment_milestone, only: [:edit, :update, :destroy]
def index
end
def new
@milestone = Budget::Investment::Milestone.new
end
def create
@milestone = Budget::Investment::Milestone.new(milestone_params)
@milestone.investment = @investment
if @milestone.save
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
notice: t('admin.milestones.create.notice')
else
render :new
end
end
def edit
end
def update
if @milestone.update(milestone_params)
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
notice: t('admin.milestones.update.notice')
else
render :edit
end
end
def destroy
@milestone.destroy
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
notice: t('admin.milestones.delete.notice')
end
private
def milestone_params
image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
documents_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
attributes = [:title, :description, :publication_date, :budget_investment_id,
image_attributes: image_attributes, documents_attributes: documents_attributes]
params.require(:budget_investment_milestone).permit(*attributes, translation_params(params[:budget_investment_milestone]))
end
def load_budget_investment
@investment = Budget::Investment.find(params[:budget_investment_id])
end
def load_budget_investment_milestone
@milestone = get_milestone
end
def get_milestone
Budget::Investment::Milestone.find(params[:id])
end
def resource_model
Budget::Investment::Milestone
end
def resource
get_milestone
end
end