0
votes

In rails app, we would like to specify both rows and value for a text column in simple form. It is easy to do with one:

<%=f.input :column, :input_html => {:rows => 5}%>
<%=f.input :column, :input_html => {:value => 'abc'}%>

We tried the following for 2 attributes:

<%=f.input :column, :input_html => {:rows => 5, :value => 'abc' }%>

Only the :value works and there is only single row instead of 5. The following causes syntax error:

<%=f.input :column, :input_html => {{:rows => 5}, {:value => 'abc' }}%>

What's the right way to specify 2 attributes in input_html? Or it is not doable. Thanks.

UPDATE: Here is the html source for the text column:

<div class="input string optional onboard_engine_config_argument_value"><label class="string optional control-label" for="onboard_engine_config_argument_value">变量值</label><input class="string optional span12" id="onboard_engine_config_argument_value" name="onboard_engine_config[argument_value]" rows="5" size="50" type="text" value=" ....."</div>

The value = "..." is a extremely long text which is a html.erb file and is displayed not in its original order. We are trying to make it displayed in its original order.

1
What's the datatype of this column? It only generates a textarea if the db column is text (for postgres)Eyeslandic
What is the generated output?Eyeslandic
Not sure what's your question. It was all the text in one row instead of in 5 rows.user938363
Try adding 'as: :text' <%= input :column, input_html: {..}, as: :text %>Eyeslandic
It works. I will mark it if you post it again as answer. thanks.user938363

1 Answers

3
votes

The reason it doesn't seem to work is because simple_form generates an input instead of a textarea. To force it to render a textarea do it like this.

<%= input :column, input_html: { rows: 4, value: "some long text"}, as: :text %>

The as: :text part forces it to render a textarea.