Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"

like image 509
Kush Avatar asked Nov 09 '13 21:11

Kush


2 Answers

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

What I think you’re after.

like image 86
Deej Avatar answered Nov 12 '22 19:11

Deej


Have you tried something like this?

<%= text_field_tag :card_number, nil, name: nil, :placeholder => "Card Number", "data-stripe" => 123 %>
like image 20
Niels B. Avatar answered Nov 12 '22 17:11

Niels B.