Module: BulmaFormRails::SubformHelpers
- Defined in:
- lib/bulma_form_rails/subform_helpers.rb
Overview
Instance Method Summary collapse
-
#bulma_child_objects(collection, name, attributes_key, add_child_path, options = {}) ⇒ Object
Renders a child objects collection management UI subform, including row addition and deletion buttons by default.
Instance Method Details
#bulma_child_objects(collection, name, attributes_key, add_child_path, options = {}) ⇒ Object
Renders a child objects collection management UI subform, including row addition and deletion buttons by default.
-
collection- an array of serializable objects -
name- the lower-case singular name of the object for display purposes -
attributes_key- a symbolic key into the attribute reference hash retrievable via thelookup_attributes(key)method defined on the controller as ahelper_method, eg:objectfor:{object: ["attribute_1", "attribute_2"]} -
add_child_path- the controller URL path for the action to add a child object to the collection -
options- a hash of additional options to pass to the partials-
system_controlled-trueif you want no row add or delete buttons,falseor unspecified if you do want add and delete buttons -
total_columns- an array of integers representing column numbers requiring arithmetic totals at the bottom of the subform, eg:[3, 4] -
container- a string representing an array index expression for a row if not a single index, eg:"[related_reservations][#{}]"
-
To use this helper method, you will first need to do the following:
-
Call
bulma_child_formsfrom the specific controller (but outside any existing method definitions) for your view, passing in a hash of the object collections to be managed along with their attributes, for example,{object1: %w[attr1 attr2], object2: %w[attr3 attr4]}. -
Add a route to the
add_childaction for the same controller, for example,put 'users/add_child', to: 'users#add_child'.
27 28 29 |
# File 'lib/bulma_form_rails/subform_helpers.rb', line 27 def bulma_child_objects(collection, name, attributes_key, add_child_path, = {}) render partial: 'bulma_form_rails/children', object: collection, locals: {url: add_child_path, name: name, attributes_key: attributes_key}.merge() end |
