method

to_form_params

Importance_2
v6.1.7.7 - Show latest stable - 0 notes - Class: ActionView::Helpers::UrlHelper
to_form_params(attribute, namespace = nil) private

Returns an array of hashes each containing :name and :value keys suitable for use as the names and values of form input fields:

to_form_params(name: 'David', nationality: 'Danish')
# => [{name: 'name', value: 'David'}, {name: 'nationality', value: 'Danish'}]

to_form_params(country: { name: 'Denmark' })
# => [{name: 'country[name]', value: 'Denmark'}]

to_form_params(countries: ['Denmark', 'Sweden']})
# => [{name: 'countries[]', value: 'Denmark'}, {name: 'countries[]', value: 'Sweden'}]

An optional namespace can be passed to enclose key names:

to_form_params({ name: 'Denmark' }, 'country')
# => [{name: 'country[name]', value: 'Denmark'}]
Show source
Register or log in to add new notes.