您好我正在尝试为已经制作的项目创建一个后台(该项目完全正常工作)
我在上传文件时遇到问题,当我尝试创建新的Training时,服务会抛出回滚。如果我将照片留空,则通常会创建培训
控制器:
def create
service_params = permitted_attributes
service_params = service_params.merge(owner_user: User.find(service_params[:owner_user]))
service = CreateTrainingService.new(service_params)
if service.call
redirect_to training_path(service.training)
else
redirect_to trainings_path
end
end
服务:
def create_training
@training = Training.new(
owner_user: @owner_user,
owner_club_id: @owner_club_id,
name: @name,
description: @description,
address: @address,
city: @city,
country: @country,
level_id: @level_id || Level.first.id,
public: @public || false,
distance: @distance,
start_date: DateTime.strptime(@start_date + ' ' + @start_time, "%d-%m-%Y %H:%M"),
road_type: @road_type,
race: @race,
participants_limit: @participants_limit,
latitude: @latitude,
longitude: @longitude,
google_place_id: @google_place_id,
cover_input: @cover,
default_cover: @default_cover,
open_runner_link: @open_runner_link,
disciplines: @disciplines
)
end
这是观点的相关部分:
<div uk-form-custom>
<%= f.file_field :cover %>
<button class="uk-button uk-button-default uk-margin-top" type="button" tabindex="-1">Select file</button>
</div>