SamuraiBlue
SamuraiBlue

Reputation: 861

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.

Upvotes: 2

Views: 2588

Answers (2)

Roman Kiselenko
Roman Kiselenko

Reputation: 44370

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 %>

enter image description hereenter image description hereenter image description hereenter image description here

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

enter image description here

enter image description here

I hope you understand this.

Upvotes: 1

Rajarshi Das
Rajarshi Das

Reputation: 12320

Try this size option was there

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

Upvotes: 1

Related Questions