Setting class and value in simple form (Rails)

balanv picture balanv · Jul 4, 2012 · Viewed 14.6k times · Source

I am using simple form in my Rails application, i tried to set value and class to a specific input field just like below

<%= f.input :email, :required => true, :autofocus => true, :value => "Email", :class => "myclass" %>

Html output :

enter image description here

but i could not able to see value and class set in the actual html form.

What am i doing wrong?

Answer

KARASZI Istv&#225;n picture KARASZI István · Jul 4, 2012

I'm not using the simple_form plugin for Rails, but as the documentation says you should use the :input_html attribute for this.

Do the following:

<%= f.input :email, :required => true, :autofocus => true, :input_html => { :value => "Email", :class => "myclass" } %>