DEV Community


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

Oldest comments (0)

11 Tips That Make You a Better Typescript Programmer


1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields


Read the whole post now!