1

For example, "required."

Rails chokes on any attempt to add the attribute thus:

<%= f.email_field :email, :"ng-model" => "whatever", :class => "form-control input-lg", :"required" %>
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Michael P.
  • 1,373
  • 3
  • 12
  • 33

2 Answers2

4

Just use boolean values:

<%= f.email_field :email, :"ng-model" => "whatever", :class => "form-control input-lg", :"required" => true %>
Claudi
  • 5,224
  • 17
  • 30
  • 2
    Beat me to it, I was just coming back with [the documentation link](http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag). – pjmorse Nov 04 '14 at 16:53
  • Interestingly enough, this outputs required="required" in my HTML. Is this to be expected? – Michael P. Nov 04 '14 at 16:56
  • The magic behind form helpers translates the Ruby constant "true" to the appropriate attribute value according to HTML standards. See this: http://stackoverflow.com/questions/7089584/html-why-boolean-attributes-do-not-have-boolean-value – Claudi Nov 04 '14 at 16:58
1

You must do the same as you do with class, add html_attribute => value

<%= f.email_field :email, :"ng-model" => "whatever", :class => "form-control input-lg", :"required" => true %>
Alejandro Babio
  • 5,189
  • 17
  • 28