Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the length of a text_field in rails?

So I have this text field

<%= f.text_field :body, placeholder: "Make an offer ", :maxlength=>"254" %> 

right now it takes up 100% of the width of the box it is in. I want it to take up like 95%. So far I have tried (from other forum posts)

adding :columns => "50" this didn't affect it. I tried putting on an html tag , :html => { :id => "offer_form" } and then putting in my css file

#offer_form { width:50%;} 

this didn't work

any other suggestions?

edit:

I realized that in my css file I have under /forms/

input, textarea, select, .uneditable-input {
  border: 1px solid #bbb;
  width: 98%;
  padding: 10px;
  height: auto !important;
  margin-bottom: 15px;

}

and when i change the width here it works. but it affects all of the forms in the entire app (obviously)(ie they are all 98%). Is there a way that I can id just this field so that I can edit its width independently.

like image 831
klondike-5-3226 Avatar asked Oct 25 '12 22:10

klondike-5-3226


2 Answers

add :size=>"50" option to text_field

<%= f.text_field :body, :size=>"50", placeholder: "Make an offer ", :maxlength=>"254" %> 
like image 105
alex Avatar answered Nov 11 '22 22:11

alex


Use CSS. The width of the field isn't related to its maximum characters.

input.body {
  width:95%;
}
like image 28
meagar Avatar answered Nov 11 '22 20:11

meagar