Search code examples
ruby-on-railshamlform-for

How to add a class to the form_for helper in a Rails 4 app?


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.


Solution

  • 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!