Custom HTML attribute requires a custom helper?

前端 未结 2 840
别跟我提以往
别跟我提以往 2021-02-18 23:48

I\'m trying to create a form with some custom data attributes on the inputs:


This seemed

2条回答
  •  无人共我
    2021-02-18 23:58

    Rails >3.1 has a handy shortcut for data-attributes like this which most HTML-generating helpers support:

    <%= f.text_field :question, :data => { :submit_clear => '1' } %>
    

    It can make things more readable when you have a couple of data attributes, e.g.:

    <%= f.text_field :question, :data => { :submit_clear => '1', :more_info => 'Ok', :also => 'this' } %>
    

提交回复
热议问题