DEV Community

mhcrocky
mhcrocky

Posted on

 

How to add CSS class in Ruby on rails form elements

This post is just a mere attempt to log-in what I have learnt about Ruby on rails Form and is not a tutorial but I know this will help those who have just began to learn Rails.

I started to building project using bootstrap and ruby on rails and meet some problem.

I wanted to use form-control class in the input tag to style it, but it didn't work.
So I did a Google search and found the results, but it took me a while.

The reason I want to write this article is because I don't want other people like me to waste their time.

You can add class using following codes


<% form.password_field(:account, class: "form-control") %>

Enter fullscreen mode Exit fullscreen mode

You can add other attributes to this field.

<% form.password_field(:account, class: "form-control" , data:"dsfsdfsdf") %>

Enter fullscreen mode Exit fullscreen mode

If this article help you I will be happy

Latest comments (0)

DEV The only reason people scroll to the bottom...Β 
is because they want to read more.

Sign up for an account to bookmark, comment, and react to articles that interest you.