Question

First off, I'm not using ActiveRecord but Sequel, so a lot of helpers like build are not available to me.

I want to something like this:

model.children_models.each do |child_model|
  semantic_fields_for child_model do |f|
    f.input ...
  end
end

Unfortunately, I encounter two problems:

  1. The input fields all have the same name and thus overwrite one another. I've gotten around this by manually doing something like semantic_fields_for "child_model[1]" and having logic to handle this in the controller

  2. I don't know how to fix inline form errors for the child model fields.

Any suggestions?

Was it helpful?

Solution

Figured it out.

Need to use this Sequel plugin: http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Plugins/NestedAttributes.html

plugin :nested_attributes
nested_attributes :children_models

Then just do something like this:

model.children_models.each do |child_model|
  semantic_fields_for :children_models, child_model do |f|
    f.input ...
  end
end

There's a few quirks as to how Sequel interacts with forms, but most can be figured out from reading.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top