Closed kbighorse closed 10 years ago
Hi, @kbighorse
I think the missing piece for the encryption is the patch here:
https://github.com/lyang/braintree-rails-example/blob/master/lib/rails_ext/tag_helper_ext.rb
As to the params hash, I don't know the exact cause of it.
Seems the live example at http://braintree-rails-example.herokuapp.com/transactions/new generates the correct name. Maybe it's ruby version?
The code that supposed to remove the 'braintree_rails' part from the 'braintree_rails_transaction' is at https://github.com/lyang/braintree-rails/blob/master/lib/braintree_rails/model.rb#L2
The code above should take care of the namespace, the rest of the naming should be handled by https://github.com/lyang/braintree-rails/blob/master/lib/braintree_rails/model.rb#L11
Hmm, adding tag_helper_ext.rb
didn't help.
The problem is that the same HAML:
# /app/views/transactions/_form.haml
= cc.input :number, :input_html => { 'data-encrypted-name' => true }
produces different HTML:
My app:
<input class="string required"
data-encrypted-name="true"
id="braintree_rails_transaction_credit_card_number"
name="braintree_rails_transaction[credit_card][number]"
required="required"
size="50"
type="text" />
Example app:
<input class="string required"
data-encrypted-name="transaction[credit_card][number]"
id="transaction_credit_card_number"
size="50"
type="text" />
It's not replacing the name
attribute with data-encrypted-name
, but rather is adding data-encrypted-name
as true
as well as name
.
There's too much magic in the example app that is actually necessary for it to work I think.
I think the problem is the tag_helper is not loaded.
I agree the helper isnt very obvious at first. A more explicit way of implementing it is probably better.
Thanks for the feedback.
Sent from my iPhone
On May 1, 2013, at 18:24, Kimball Bighorse notifications@github.com wrote:
The problem is that the same HAML:
/app/views/transactions/_form.haml
= cc.input :number, :input_html => { 'data-encrypted-name' => true } produces different HTML:
My app:
<input class="string required" data-encrypted-name="true" id="braintree_rails_transaction_credit_card_number" name="braintree_rails_transaction[credit_card][number]" required="required" size="50" type="text" /> Example app:
<input class="string required" data-encrypted-name="transaction[credit_card][number]" id="transaction_credit_card_number" size="50" type="text" /> It's not replacing the name attribute with data-encrypted-name, but rather is adding data-encrypted-name as true as well as name.
There's too much magic in the example app that is actually necessary for it to work I think.
— Reply to this email directly or view it on GitHub.
Is there a way to make sure it loads?
I explicitly required it in the initializers, like https://github.com/lyang/braintree-rails-example/blob/master/config/initializers/braintree.rb#L1
awesome, that fixed that. I'll leave this open in case someone figures out the model name thing.
in formtastic I ensured that by adding :name=>nil
to the fields.
<%= f.input :number, :label => 'Card Number', input_html: { "data-encrypted-name" => "credit_card[number]", :name => nil } %>
generates
<div class="controls">
<input data-encrypted-name="credit_card[number]" id="credit_card_number" type="text">
</div>
Working from the
braintree-rails-example
code, copied this from TransactionsController:Getting this error in #create:
TypeError (can't convert nil into Hash):
Sure enough:
(also curious is that the CC data aren't being encrypted)
My form is exactly the same as https://github.com/lyang/braintree-rails-example/blob/master/app/views/transactions/new.html.haml and https://github.com/lyang/braintree-rails-example/blob/master/app/views/transactions/_form.html.haml, so I won't copy them here.
I will post the relevant generated HTML: https://gist.github.com/kbighorse/5497038.
I'll just use
params[:braintree_rails_transaction]
in the meantime, but pretty sure something went wrong between the controller and the view.