Hello. Faced with a situation unfamiliar to me, in the development of a novice, I need advice.
There is a controller with the action 'update'
def update @arrival = find_arrival @details = @arrival.arrival_details if check_conditions(@arrival) flash[:notice] = 'Документ прихода отредактирован' else flash[:error] = 'Возникла ошибка. Проверьте правильность заполнения формы' end redirect_to edit_admin_arrival_path(@arrival) end as well as the following private methods:
def check_conditions(arrival) new_status = arrival_params[:status] case @arrival.status when 'draft' return unless check_dependencies recalculate_balance if new_status == 'accrued' @arrival.update(arrival_params) when 'canceled' return unless new_status == 'draft' @arrival.update(status: arrival_params[:status]) when 'accrued' return if new_status == 'draft' recalculate_balance if new_status == 'canceled' @arrival.update(new_status) end end def recalculate_balance puts '[PRY] recalculated' end def check_dependencies Provider.exists?(arrival_params[:provider_id]) && Warehouse.exists?(arrival_params[:warehouse_id]) end Interests the following - whether it is worth making this condition in a separate class or any Service Object? I do not think that such a huge condition is a place in the controller. What can you advise?