Question

I am trying to refactor a model using best practices, which I assume would be Active Record.

 class WEBOEL23 < ActiveRecord::Base
 establish_connection "as400_#{RAILS_ENV}"
 set_table_name "WEBOEL23"  

    def get_email 
      @weboe123 = WEBOEL23.EMAL23    
      where @weboel23
 end
end

I am calling this in models/order.rb In order.rb I am looking for an email out of the weboel23 table.(which is a logical file from a AS400) When this code is executed it returns a NameError (uninitialized constant Order::EMAL23)

 if sign_on.acctypw1.strip == "DS" or sign_on.acctypw1.strip == "DSD" 

if approval0!=""  

                            Mailer.deliver_order_distributor_approval_email(Weboel23.get_email, "Coastal Pet Online Ordering<noreply@coastalpet.com>", "DIST Confirmation-0 ", email_details)

end 

I have tried all of the suggestions below and yes I am still learning but I really need some guidance to get past this error

No correct solution

OTHER TIPS

I don't know from which language you come from but you definitively don't use the ruby and rails Style.

  • First of all, you use find_email_by_account act223 and you assign a variable so why to you call this method.
  • Secondly, d= "", what is d. In ruby, and in programation in general, is better to use explicit name.
  • For !act223.blank?, there is this method act223.present?.
  • What is s in s = @email.where ["EMAL23=?" ]?
  • Where come from variable @email or act223?

For you error, a file called weboel23 must define a model called Weboel123.

You should probably do an instance method callable like this @account.email.

I suggest to build a model like this :

class WEBOEL23 < ActiceRecord::Base
  establish_connection "as400_#{RAILS_ENV}"
  set_table_name "WEBOEL23"

  def email
    WEBOEL23.where(ACT223: act223).first.email
  end
end

So you can use it like this :

@weboel23.email

I don't know if this is the best practice because I don't know what is ACT223 or weboel23.

I agree with the comment of @bjhaid. Take a pause and read about ruby and rails.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top