Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby class initialize error - undefined method 'has_key?'
    primarykey
    data
    text
    <p>So I was following this <a href="http://old.nycdevshop.com/blog/balanced-payments-part-1" rel="nofollow">Balanced Payments tutorial</a>, and tried tweaking their Payment model to fit my application.</p> <p>Original:</p> <pre><code>class Payment def initialize(email, amount, credit_card_hash) @email = email @amount = (amount * 100).to_i @credit_card_hash = credit_card_hash @buyer = nil @card = nil @errors = [] end end </code></pre> <p>My simplified version (Updated with code of full model):</p> <pre><code>require 'balanced' class Transaction &lt; ActiveRecord::Base attr_reader :errors, :amount def initialize(amount) @amount = (amount * 100).to_i @buyer = nil @card = nil @errors = [] end def charge begin find_or_create_buyer debit_buyer credit_owner return true rescue return false end end private def find_or_create_buyer begin @buyer = current_user.balanced_customer rescue @errors &lt;&lt; 'Your account is invalid' end end def debit_buyer begin payment = @buyer.debit(@amount, "Test transaction") rescue @errors &lt;&lt; 'Your credit card could not be charged' end end def credit_owner begin Balanced::Marketplace.my_marketplace.owner_account.credit(amount) rescue @errors &lt;&lt; 'Your credit card payment did not go through.' end end end </code></pre> <p>The problem is I'm getting what seems like a pure ruby error every time I try to instantiate the class from the rails console,</p> <pre><code>&gt; payment = Transaction.new(0.01) output error: #&lt;NoMethodError: undefined method `has_key?' for nil:NilClass&gt; </code></pre> <p>I've googled around and haven't been able to come up with a good answer.</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload