Search code examples
ruby-on-railsrubyruby-on-rails-4stripe-payments

How to add data-stripe attribute to text_field_tag?


In the Stripe documentation, the example form shows the following input

<input type="text" size="20" data-stripe="number"/>

I'm using the following code in ruby (rails 4) to generate my input

<%= text_field_tag :card_number, nil, name: nil, :placeholder => "Card Number" %>

which generates

<input id="card_number" placeholder="Card Number" type="text" />

However, I'm unable to add the data-stripe attribute. I guess I could always add the field manually and not use rails feature. However, it'll be tedious to replace other functions such as select_year and select_month. So, how can I add a custom attribute when generating an input using rails? Specifically, data-stripe="number"


Solution

  • <%= text_field_tag :card_number, nil, name: nil, placeholder: "Card Number", data: { stripe: 'number' } %>
    

    What I think you’re after.