我正在为一个学校项目构建一个简单的基于 Rails 的旅行应用程序。
我想制作一个表单,使用户能够输入数据,例如他们的旅行名称、两个目的地,并且每个目的地都有一个位置。
如何使用三重巢形式做到这一点?
我现在对构建方法感到非常困惑。下面是控制器中的 def 新方法和私有方法。
class TripsController < ApplicationController
def new
@trip = Trip.new
Destination.all.each do |destination|
@trip.destinations.build.location
end
private
def set_trip
@trip = Trip.find(params[:id])
end
def trip_params
params.require(:trip).permit(:name, :start_date, :end_date,
:destination_1, :destination_2, :user_id, :destinations_attributes => [:name,
:locations_attributes => [:name]
]
)