Custom HTML attribute requires a custom helper?

前端 未结 2 829
别跟我提以往
别跟我提以往 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:53

    Oops. It's just

    <%= f.text_field :question, :id=>"poll_question", :class=>"BigInput", :style=>"width:98%;", 'data-submit_clear'=>'1' %>
    
    0 讨论(0)
  • 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' } %>
    
    0 讨论(0)
提交回复
热议问题