加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用simple_form进行多行文本输入

发布时间:2020-12-17 03:49:56 所属栏目:百科 来源:网络整理
导读:我有这样的形式: %= 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"
我有这样的形式:

<%= 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将根据数据库中的类型选择元素.如果comment是string类型(而不是text),它将使用一个输入字段,该字段没有rows属性.

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

<%= p.input :comment,as: :text,:input_html => {:style => 'width: 100%',class: 'response-project'} %>

这可以像this guy那样解决您的问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读