0

In a 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 achievable?

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.

9
  • What's the datatype of this column? It only generates a textarea if the db column is text (for postgres) Commented Jun 10, 2014 at 17:34
  • What is the generated output? Commented Jun 10, 2014 at 17:39
  • Not sure what's your question. It was all the text in one row instead of in 5 rows. Commented Jun 10, 2014 at 17:47
  • 1
    Try adding 'as: :text' <%= input :column, input_html: {..}, as: :text %> Commented Jun 10, 2014 at 18:15
  • 1
    It works. I will mark it if you post it again as answer. thanks. Commented Jun 10, 2014 at 19:03

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.