【问题标题】:Rails text_area sizeRails text_area 大小
【发布时间】:2010-11-19 10:04:05
【问题描述】:

我在fields_for 内有一个text_area,它在form_for 内。

<%= day_form.text_area :hatch %>

是否可以更改text_area 的大小?例如:day_form.text_area size: 5

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    你可以选择:

    <%= day_form.text_area :hatch, cols: 30, rows: 10 %>
    

    或者你可以同时指定 size 属性:

    <%= day_form.text_area :hatch, size: "30x10" %>
    

    【讨论】:

    • 这现在不起作用了,是否有与此不同的 rails 3.1 解决方案?
    • 这个我没看到,不过你也可以这样写: "60%x5%" %> This在 Rails 4.0.0 中
    • 我不得不将 f.text_field 更改为 f.text_area。
    【解决方案2】:

    为了响应,我喜欢将文本区域宽度设为 100%:

    &lt;%= f.text_area :description, rows: 10, style: 'width:100%;' %&gt;

    【讨论】:

      【解决方案3】:

      由于文本区域同时具有行和列,因此您必须同时指定两者

      <%= text_area(:application, :notes, cols: 40, rows: 15, class: 'myclass') %>
      

      对于文本字段可以使用

      <%= text_field(:application, :name, size: 20) %>
      

      http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-text_area

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-25
        • 2021-04-07
        • 1970-01-01
        • 1970-01-01
        • 2011-04-12
        • 1970-01-01
        • 2013-10-02
        相关资源
        最近更新 更多