Per this pull request I see that the array should be passed to the form_with model parameter. However, when I put the following:
<%= form_with(model: [@trip, @activity], local: true) do |f| %> ... <% end %>
Rails will return - ActionView::Template::Error (undefined method activity_path' for #<#<Class:0x007f80231e3070>:0x007f8023010dd8>):
My routes file looks like this:
resources :trips do resources :activities end
The output of rake routes looks like
trip_activities GET /trips/:trip_id/activities(.:format) activities#index POST /trips/:trip_id/activities(.:format) activities#create new_trip_activity GET /trips/:trip_id/activities/new(.:format) activities#new edit_trip_activity GET /trips/:trip_id/activities/:id/edit(.:format) activities#edit trip_activity GET /trips/:trip_id/activities/:id(.:format) activities
And my activity_controller.rb is
before_action :set_activity, only: %i[show update edit destroy] def edit; end def update dates = calculate_datetimes(params[:date_range]) @activity.assign_attributes(name: params[:name], summary: params[:summary], start_datetime: dates[0], end_datetime: dates[1]) if @activity.save flash[:success] = 'Activity successfully updated' redirect_to(@trip) else set_humanized_daterange render :edit end end private def set_activity @activity = Activity.find(params[:id]) end
tl; dr - how do I configure my form_with for a nested resource, and why do I want to use activity_path for this form of thinking? Ideally, I would like to move this form to partial and use the same form for my #new and #edit actions.
source share