Domanda

I'm using bootstrap CCS to style my Rails 4 app, but cannot figure out how to add a class to the form when using the form_for helper. I have followed the suggestions on several other threads without success. Two such threads...

The app works as it should per the instructions, but I want it to look good too. Here is the working code and have commented out the first line as it does not add the additional class to the form as I need it to.

Can anyone help with this challenge? Hopefully there is some smart Rails developers available to help out today.

È stato utile?

Soluzione

You might have got your answer,though these are some points might help you

form_for with class name in haml:

= form_for @patient, :html => {:class => "form-horizontal"} do |f|

it can also be written as

= form_for @patient, {:html => {:class => "form-horizontal"}} do |f|

but it couldn't be written as

- form_for @patient, :html => {:class => "form-horizontal"} do |f| #it gives error.

Hope it helps!

Altri suggerimenti

In addition to Pavan's answer in Rails 4 you can simply write it this way if you are using a form_tag:

= form_tag some_path, method: 'get', class: 'some-class' do

This worked for me.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top