简体   繁体   中英

Rails 4 : How to change the size of text_field

I'd like to change the size of text_field, but it doesn't work.

new.html.erb

<div class="row">
  <%= form_for(@user) do |f| %>
    <%= render 'fields', f: f %>
    <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
  <% end %>
</div>

_fields.html.erb

<%= f.label :name %>
<%= f.text_field :name, size: 10 %>

size: 10 doesn't work.

This is worked example, you doing some wrong, i belive you have some css style that override you text field :

<%= f.text_field :user, size: 10 %>

在此处输入图片说明在此处输入图片说明在此处输入图片说明在此处输入图片说明

If i delete class from submit, place </br> , set 0 width in css, and now i see size of the text_field

在此处输入图片说明

在此处输入图片说明

I hope you understand this.

试试这个size选项

 <%= f.text_field :name, :size=>"10" :maxlength=>"254" %> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM