Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple_form text input

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?

like image 707
Kyle Decot Avatar asked Mar 12 '12 00:03

Kyle Decot


2 Answers

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".

like image 102
Andrew Marshall Avatar answered Sep 18 '22 00:09

Andrew Marshall


I will update the answer to this question, because the new way to do that with simple_form is like this:

f.input :foobar, as: :text

As you can see, using the "as: :text" will use a text_area field, but if you want to modify the amount of rows and cols you should do it like this:

f.input :foobar, as: :text, input_html: {rows: 10, cols: 10}

Here you can see the documentation for the gem:

https://github.com/plataformatec/simple_form

like image 33
Demi Magus Avatar answered Sep 18 '22 00:09

Demi Magus