Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add styling to a single input in a form_for

I'm using the rails framework with HAML and I have bootstrap setup. How would I format the field inputs seperately. I want the input field for name to be 60% of the screen float left and the input for price to be 25% of the screen and float right.

I guess i'm asking how do i add classes to single inputs in a form_for. Thanks

= form_for @product,:url => products_path, :html => { :id => "fileupload", :multipart => true } do |f| 
  %p
    = f.label :name
    = f.text_field :name # i want to format this
  %p
    = f.label :price
    = f.text_field :price
like image 485
Alain Goldman Avatar asked Jul 06 '13 20:07

Alain Goldman


People also ask

What is form tag in Ruby on Rails?

The form_tag Rails helper generates a form withe the POST method by default, and it automatically renders the HTML that we were writing by hand before. Note: We can explicitly specify what HTTP verb to use for the form_tag if we want something other than POST .

What is local true in Rails form?

This setting determines whether form_with generates remote forms or not. It defaults to true. Or maybe more commonly set in config/application.


1 Answers

you can add a class to any form helper and use CSS to format it:

= f.text_field :name, class: 'your_class' # i want to format this

of cause you can also set a style option directly, but it is recommended to separate content and styling. So don't

= f.text_field :name, style: 'float: left; width: 60%; display: block' # i want to format this
like image 110
Martin M Avatar answered Sep 25 '22 17:09

Martin M