simple_form text input

Kyle Decot picture Kyle Decot · Mar 12, 2012 · Viewed 15.7k times · Source

I'm switching my application over to use simple_form but I'm a little confused about how to display a text input. For instance when I do the following:

f.input :foobar # <textarea name = "model[foobar]"></textarea>

I get a textarea instead instead in input w/ a type of text. How can I force simple_form to output a text input?

Answer

Andrew Marshall picture Andrew Marshall · Mar 12, 2012

it's happening because the field is a text column in the database, rather than string/varchar/etc., you can override the default like so:

f.input :foobar, :as => :string

You can read about all the mappings in the simple_form readme under "Mappings/Inputs available".