Thank you for re-launching this board! As I wanted to try it out, I could not resist to cross-post this question.
In my project I generated a form object that handles the connection to multiple models. It looks like this
class StationForm include Virtus include ActiveModel::Model # I think this is unnecessary # extend ActiveModel::Naming # include ActiveModel::Conversion # include ActiveModel::Validations # Station attr_reader :station attribute :station_name, String attribute :station_description, String # Address attr_reader :address attribute :address_url, String attribute :address_priority, Integer attribute :address_is_active, Boolean def persisted? false end def save if valid? persist true else false end end private def persist @station = Station.create(name: station_name, description: station_description) @address = @station.addresses.create(url: address_url, priority: address_priority, is_active: address_is_active) end end
This works well to generate new stations and their addresses. Here is the related code in the controller
class StationsController < ApplicationController def new @station_form = StationForm.new end def create @station_form = StationForm.new(station_form_params) @station_form.save redirect_to station_path(@station) end private def station_form_params params.require(:station_form).permit(:station_name, :station_description, :address_url, :address_priority, :address_is_active) end end
Now, I don't succeed to enhance this form object and controller for the edit and update methods.
Can you help me to do so?
Thank you in advance!