-1

Can somebody help me to resolve this?

LoadError: Unable to autoload constant BankAccounts::ValidateNewTransaction, expected /home/amd/bank/app/operations/bank_accounts/validate_new_transaction.rb to define it

Even with require_dependency it is not working.

CDspace
  • 2,639
  • 18
  • 30
  • 36
Michael
  • 45
  • 1
  • 7
  • How about you post the `BankAccounts::ValidateNewTransaction` code? And, verify that it's in the correct location. And, stop your server, run `spring stop`, and restart your server. – jvillian May 22 '17 at 15:12
  • this is my code – Michael May 22 '17 at 20:58

2 Answers2

5

As a wild guess, do you define your class like this:

  module BankAccounts
    class ValidateNewTransaction

      ...

    end
  end

If so, you might want to try:

  class BankAccounts::ValidateNewTransaction

    ...

  end

That helped here.

Also, in your comment, you wrote:

  module BankAccounts 
    class ValidateNewtransaction 
      def initialize(amount:, transaction_type:, bank_account_id:) end

Is that from your actual code? Because, you have ValidateNewtransaction, not ValidateNewTransaction (the T needs to be upper case).

jvillian
  • 19,953
  • 5
  • 31
  • 44
  • module BankAccounts class ValidateNewtransaction def initialize(amount:, transaction_type:, bank_account_id:) end – Michael May 22 '17 at 21:45
  • 2
    Please don't add code in comments. You can add it to your original question. It's too hard to look at in comments. – jvillian May 22 '17 at 21:57
  • Did you try the class declaration all on one line? Making sure spring isn't running? – jvillian May 22 '17 at 22:06
  • oh sorry ! you right about the t it wasnt upper i just see the mistake ! – Michael May 22 '17 at 22:21
  • Super, glad to help. Please feel free to accept the answer if you see fit. – jvillian May 22 '17 at 22:25
  • i have an another error NoMethodError: undefined method `<<' for nil:NilClass from app/operations/bank_accounts/validate_new_transaction.rb:31:in `validate_existence_of_account!' – Michael May 22 '17 at 22:40
  • def validate_existence_of_account! if @bank_account.blank? @errors << "Account not found" end end – Michael May 22 '17 at 22:41
  • 1
    How about you accept this answer. Then post the new question separately and I'll take a look at it. – jvillian May 22 '17 at 22:47
0

This error is typically caused by not defining your classes in the correct files. Have you double-checked that app/operations/bank_accounts/validate_new_transaction.rb actually defines exactly that class? (BankAccounts::ValidateNewTransaction).

You can read some more about this at Rails Guides, in 6.1.2 "Top Level Constants" mentions that exact error - LoadError.

Frederik Spang
  • 3,379
  • 1
  • 25
  • 43