It couldn’t last

It didn’t take long for my development with polymorphic associations and forms to founder.

The very next stage after my last post on the matter, in fact. And I now have a second reference source that, while providing an additional nudge, isn’t enough to see me through the current block.

To be able to nest the activity section on the commission form, we need to tell the commission model to accept activity fields,

accepts_nested_attributes_for :activities

(I originally hd this as :activity after the model name, but it gave a missing model error; then my initial hunch was probably that accepts_nested_attributes_for was no longer supported in Rails 5; these things rarely work for very long).

A quick search on the topic of continued rails support for accepts_nested_attributes_for took me to https://rubyplus.com/articles/3681-Complex-Forms-in-Rails-5, which is a nicely written page which only backs up my original source. Curiously, however, it includes a step that shows successful data posts before they’ve been added to the form.

Then we simply add the following to the commission form,

 <% f.fields_for :activities do |act| %>
 Title: <%= act.text_field :title %>
 Details: %= act.textarea :details %>
Number of slots: <%= act.number_field :number_of_slots %>
 Min slot separation: <%= act.number_field :min_slot_separation %>
 <% end %>

Then nothing. No errors, log messages or anything. Nothing. Nothing ever works the way it’s described and a heavy price is to be paid for every advance.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s