我的控制器中有以下内容:
@custom_exercises = @user.exercises.all
@all_exercises = Exercise.not_the_placeholder_exercise.public.order("name").all
if @user.trainers.present?
trainer_exercises = []
@user.trainers.each do |trainer|
trainer_exercises << trainer.exercises.all
end
@my_trainer_custom_exercises = trainer_exercises
end
@exercises = @custom_exercises + @all_exercises
if @my_trainer_custom_exercises.present?
@exercises << @my_trainer_custom_exercises
@exercises.flatten!
end
这感觉真的很乱。我怎么能重构这个?