1
0

Allow binding goal saving w/o exposures and disallow destruction

This commit is contained in:
cryptogopher
2020-08-22 23:17:24 +02:00
parent 8f0e718b4a
commit cf0e14d87d
6 changed files with 51 additions and 33 deletions

View File

@@ -1,6 +1,13 @@
module Concerns::Finders
private
def find_goal(id = params[:id])
@goal = Goal.find(id)
@project = @goal.project
rescue ActiveRecord::RecordNotFound
render_404
end
def find_meal
@meal = Meal.find(params[:id])
@project = @meal.project

View File

@@ -22,9 +22,9 @@ class TargetsController < ApplicationController
end
def create
goal = @project.goals.binding if params[:goal][:id].blank?
goal ||= @project.goals.find_by(id: params[:goal][:id])
goal ||= @project.goals.build(goal_params)
goal_id = params[:goal][:id]
goal = goal_id.present? ? @project.goals.find(goal_id) : @project.goals.new
goal.attributes = goal_params unless goal.is_binding?
@targets = goal.targets.build(targets_params[:targets]) do |target|
target.effective_from = params[:target][:effective_from]
@@ -70,7 +70,7 @@ class TargetsController < ApplicationController
private
def goal_params
params.require(:goal).permit(:id, :name, :description)
params.require(:goal).permit(:name, :description)
end
def targets_params