使用 simple_form 的多行文本输入

Multiple row text input with 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>

我想让输入框显示5行,结果只显示1行,如何强制显示5行?

默认情况下,simple_form 将根据数据库中的类型选择元素。如果 commentstring 类型(而不是 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'} %>

这可能会像 this guy 一样解决您的问题。