Ruby on rails 提交成功后的自定义操作和正确重定向
我实际上正在开发一个小应用程序,用户可以在其中创建一个事件。必须分三步完成。 为了实现这一点,我在相关控制器中创建了两个自定义操作。每个视图都有一个使用Ruby on rails 提交成功后的自定义操作和正确重定向,ruby-on-rails,redirect,controller,Ruby On Rails,Redirect,Controller,我实际上正在开发一个小应用程序,用户可以在其中创建一个事件。必须分三步完成。 为了实现这一点,我在相关控制器中创建了两个自定义操作。每个视图都有一个使用updateurl的表单。 然后我通过以下方式自定义了更新方法: def training @event = Event.find(params[:event_id]) @coach = Coach.find(@event.coach_id) end def confirm @even
update
url的表单。
然后我通过以下方式自定义了更新方法:
def training
@event = Event.find(params[:event_id])
@coach = Coach.find(@event.coach_id)
end
def confirm
@event = Event.find(params[:event_id])
end
def update
respond_to do |format|
if @event.update(event_params)
if params[:commit] == 'next'
format.html { redirect_to booking_event_confirm_path(@event), notice: 'Event was successfully updated.' }
else
format.html { redirect_to booking_event_path(@event), notice: 'Event was successfully updated.' }
end
else
if params[:commit] == 'next
format.html { render :training }
else
format.html { render :edit }
end
end
end
end
作为一个Rails初学者,我很乐意得到一些反馈。。。这看起来还好吗,还是这是实现我目标的更好方式
提前谢谢 您的解决方案不错,但有更好的方法来实现它。我建议你检查一下
一般来说,谷歌搜索是一个向导或多步骤表单。感谢您的快速回答!顺便说一句,我正在添加验证,并注意到出现错误时,
render:training
具有奇怪的行为:显示正常,但url从booking/events/:id/training
更改为booking/events/:id
。。。有什么想法吗?又是Thx