You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/services/ecs/save_course_evaluation_serv...

35 lines
996 B

6 years ago
class Ecs::SaveCourseEvaluationService < ApplicationService
include AcceptsNestedAttributesHelper
attr_reader :ec_course, :course_evaluation, :params
def initialize(course_evaluation, params)
@course_evaluation = course_evaluation
@ec_course = course_evaluation.ec_course
@params = params
end
def call
Ecs::SaveCourseEvaluationForm.new(params).validate!
subitem_attributes = build_accepts_nested_attributes(
course_evaluation,
course_evaluation.ec_course_evaluation_subitems,
params.delete(:course_evaluation_subitems),
&method(:course_evaluation_subitem_param_handler!)
)
course_evaluation.assign_attributes(params)
course_evaluation.assign_attributes(ec_course_evaluation_subitems_attributes: subitem_attributes)
course_evaluation.save!
course_evaluation
end
private
def course_evaluation_subitem_param_handler!(item)
item[:name] = item[:name].to_s.strip
end
end