我有一个表单设置为接受日期时间值。然后,该值将作为参数发送到我的控制器方法" bookingdate"它将与预订中的其他日期进行比较,以确保没有双重预订,使用do循环。
但是,当我提交日期表单时,而不是重定向到用户选择其他详细信息的下一个表单时,它会抛出错误或重定向错误。
这是我的控制器
def bookingdate
@bookings = Booking.all
@bookings.each do |b|
if b.startdatetime == params[:startdatetime]
@musicians = Musician.where (["id != ?", b.musician_id])
end
end
render :action => 'new'
end
这是我的路线
match '/bookdate', :to => 'bookings#bookingdate'
答案 0 :(得分:1)
添加redirect_to
帮助程序并将路径传递到进度
def bookingdate
@bookings = Booking.all
@bookings.each do |b|
if b.startdatetime == params[:startdatetime]
@musicians = Musician.where (["id != ?", b.musician_id])
end
end
redirect_to path_where_you_want_to_redirect
end
我想你想要执行一些检查,如果用户有正确的填写表格
def bookingdate
@bookings = Booking.all
@bookings.each do |b|
if b.startdatetime == params[:startdatetime]
@musicians = Musician.where (["id != ?", b.musician_id])
end
end
if condition_successful
redirect_to path_where_you_want_to_redirect
else
render :bookingdate
end
end