Vani
Vani

Reputation: 71

html not working in haml/ror form_for

I am new to ror. How do I give required attribute for an input[not the required label that is provided by ruby]. When I write this,

= form.text_field :title, {html:{required: "required"}}

browser shows this,

 < input html="{:required=>&quot;required&quot;}" id="key_date_title" 
name="key_date[title]" size="30" type="text">

Upvotes: 2

Views: 173

Answers (1)

Mandeep
Mandeep

Reputation: 9173

If you look at text_field helper. It requires 3 arguments: object_name, method and options = {}. You can pass in any standard HTML attributes directly in options argument.

= form.text_field :title, required: true

Upvotes: 2

Related Questions