ruby-on-railssimple-formactionviewhelper

Rails Action View Form Helper pass options hash to create element


Given a hash of properties for a text_field to be made in HAML:

entry = {class: "form-control", disabled: true, id: :foobar}

How can I do this:

%dd!= f.send(:text_field, entry[:id], class: entry[:class], disabled: entry[:disabled])

But flexible? (So don't need placeholders, just a hash). Have looked at simple form docs and action view form helper docs and found input_html, but that's not working in this manner.

The f.send is obligatory, as :text_field can be anything. Would prefer not to use eval


Solution

  • text_field takes:

    text_field(attribute_name, input_html_options)
    

    Does

    f.text_field(entry[:id], entry)
    

    not work?