1

I have a rails code like below for input fields.

Name:-<%=text_field_tag "specification[name1]","",:class=>"autocomplete form-control"%>
<br/>

Value:-<%=text_field_tag "specification[value1]","",:class=>"autocomplete form-control"%>


I want a name and one value to be aligned horizantally to each other.

Not sure how do I go about it. I hope the question is clear.

Thanks

Suraj
  • 41
  • 8

2 Answers2

2

There are millions of ways to do this but simplest one is to use them in a table:

<table>
  <tr>
    <td>Name:-<%=text_field_tag "specification[name1]","",:class=>"autocomplete form-control"%></td>
    <td>Value:-<%=text_field_tag "specification[value1]","",:class=>"autocomplete form-control"%></td>
  </tr>
</table>
Amir Hoseinian
  • 2,312
  • 2
  • 24
  • 27
  • Well, I know we can do this. When I am using this table, my app is breaking because there are other things there as well so I don't want to do much of customizations and hence trying not to use it – Suraj Jul 12 '16 at 06:11
0

Since you are already using bootstrap, you can use the form-inline class available in bootstrap and then use a form-group class for each label and field. Just add the form-inline class to the form tag.

<form class="form-inline">
  <div class="form-group">
    <label for="exampleInputName2">Name</label>
    <input type="text" class="form-control" id="exampleInputName2" placeholder="Jane Doe">
  </div>
  <div class="form-group">
    <label for="exampleInputEmail2">Email</label>
    <input type="email" class="form-control" id="exampleInputEmail2" placeholder="jane.doe@example.com">
  </div>

This will show the two fields inline. You can you it in this way as given in the bootstrap documentation.

sidag95
  • 101
  • 6
  • Do let me know it works. And please mark the answer which worked for you as correct answer. It will help others in the future :) – sidag95 Jul 13 '16 at 11:31