Search code examples
ruby-on-railssimple-form

Setting class and value in simple form (Rails)


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?


Solution

  • 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" } %>