I would like to create a Town who have several neested attributes :
My controller :
def new
@town = Town.new(params[:user_id])
@user = current_user.id if current_user
@poi = @town.build_poi(user_id: @user)
@track = @town.poi.tracks.build
end
def create
@town = Town.new(town_params)
@town.user_id = current_user.id if current_user
if @town.save(town_params)
if params[:images]
params[:images].each do |image|
@town.town_images.create(image: image)
end
end
redirect_to root_path, notice: t(".town_created")
else
render :new
end
end
And my strong params :
def town_params
params.require(:sleep).permit(
:name,
:user_id,
{ :service_ids => [] },
{ :poi_attributes => [:id, :city, :pk, :latitude, :longitude, :poitable_id, :poitable_type, :user_id, :track_ids =>[] ] },
{ :image_attributes => [:image, :town_id]})
end
I get the following error : Unpermitted parameter: :track_ids
I try to use permit! but I always have the same error. What's wrong ?
Aucun commentaire:
Enregistrer un commentaire