Showing results for 
Search instead for 
Did you mean: 

Ruby on Rails Variables for Information

I keep getting errors when I try to use variables instead of inserting exact details. Here is my current code:


request =

@amount = session[:form_total]
request.transactionRequest =
request.transactionRequest.amount = @amount
request.transactionRequest.payment =
request.transactionRequest.payment.creditCard ='4111111111111111','0220','123')
request.transactionRequest.transactionType = TransactionTypeEnum::AuthCaptureTransaction

 For this example, it gives me an error that a valid amount is required. The issue is that it isn't just there. In, you'll see in this example that there are test numbers. Those work. However, if I replace them with variables, it will not work and will give me an error for that as well.


Any ideas? Thank you!


Hi @camerson2017,

The reason why you are getting this error is because 'amount' is not a normal variable in your case. It is an instance variable. Getting and setting instance variable is a bit different in case of ruby. The change is only reflected after it is instantiated via calling class method or while the instantiation of a class. Here's is an example:


class Hi
  def callme
    @hello = "hello"
endh =
p h.instance_variables 

h.callmep h.instance_variables

# Output



Hope this helps! 

Authorize.Net Expert Authorize.Net Expert
Authorize.Net Expert