使用simple_form进行多行文本输入

Mel*_*Mel 4 ruby-on-rails simple-form

我有这样的形式:

<%= simple_form_for @article do |m| %>
  <%= m.simple_fields_for :article_comment do |p| %>

    <%= p.error_notification %>

    <%= p.input :article_id, as: :hidden, input_html: {value: @article.id} %>
      <div class="form-inputs">
        <div class="row">
          <div class="col-md-2 col-md-offset-1">
            <%= p.label 'What do you think?', :class => 'indexsubtext' %>
          </div>
          <div class="col-md-9">
            <%= p.input :comment, label: false, autofocus: true, :input_html => {:style=> 'width: 100%', :rows => 5, class: 'response-project'} %>
          </div>
Run Code Online (Sandbox Code Playgroud)

我希望输入框显示5行,但它只显示1.如何强制它提供5?

K M*_*lam 9

默认情况下,simple_form将根据数据库中的类型选择元素.如果comment是类型string(而不是text),它将使用一个input没有rows属性的字段.

尝试添加as: :text选项.这将强制元素textarea:

<%= p.input :comment, label: false, as: :text, autofocus: true, :input_html => {:style => 'width: 100%', :rows => 5, class: 'response-project'} %>
Run Code Online (Sandbox Code Playgroud)

这可能会解决你的问题,就像这个人一样.