Jump to content

The ultimate community for Ruby on Rails developers.


Photo

find email by account using active record

ruby1.9 rails3.2 AS400 Activerecord instanceMethod

  • Please log in to reply
6 replies to this topic

#1 Bob Kendall

Bob Kendall

    Signalman

  • Members
  • 18 posts

Posted 19 February 2014 - 02:16 PM

I am trying to refactor an app that I have inherited that was not coded using rails best practices. I am fairly new to rails and I am doing the tutorials and book thing, but I also need to keep making process on the project.

 

I have a model that I have refactored:

 

models/weboel23.rb
class WEBOEL23 < ActiveRecord::Base
establish_connection "as400_#{RAILS_ENV}"
  set_table_name "WEBOEL23"  
  
  def email
     @weboe123 = WEBOEL23 
      WEBOEL23.where(ACT223: act223).first.email
  end
end
 
and I am calling it from models/order.rb:
if approval1!=""
 
Mailer.deliver_order_distributor_approval_email(@weboel23.email, "Coastal Pet Online Ordering<noreply@coastalpet.com>", "DIST Confirmation-1 ", email_details)
end
 
the error that it is returning is - NoMethodError (Undefined method 'email' for nil:NilClass): - does this mean that the email record is returning blank?  I have tried setting @weboe123 = WEBOEL23 in my def but it is still coming back undefined. Dies anyone have any insights or clues that I may be missing??
 
thank in advance for any help

 



#2 Bob Kendall

Bob Kendall

    Signalman

  • Members
  • 18 posts

Posted 19 February 2014 - 06:50 PM

I also tried:

 

models/weboel23.rb

class WEBOEL23 < ActiveRecord::Base
establish_connection "as400_#{RAILS_ENV}"
  set_table_name "WEBOEL23"  
  
    def WEBOEL23
    @weboe123 = WEBOEL23   
   end
     
   def get_email    
    @WEBOEL23.where(ACT223: act223).first.email
  end
end
 
models/order.rb
if approval1!=""
Mailer.deliver_order_distributor_approval_email(weboel.get_email, "Coastal Pet Online Ordering<noreply@coastalpet.com>", "DIST Confirmation-1 ", email_details)
end
 
executing the code this way results in the error NameError (undefined local variable or method 'weboel' )


#3 Bob Kendall

Bob Kendall

    Signalman

  • Members
  • 18 posts

Posted 20 February 2014 - 02:30 PM

I could really use some ideas on how to move forward past theses errors i think there must be something I am missing??



#4 maxgenus

maxgenus

    Passenger

  • Members
  • 2 posts

Posted 25 February 2014 - 05:59 AM

 If you want to find by a user's email, write User.find_by(:email => 'foo@bar.com') .....

 

cool contact lenses

 

big eye lenses

#5 Bob Kendall

Bob Kendall

    Signalman

  • Members
  • 18 posts

Posted 25 February 2014 - 02:14 PM

I am no longer getting any errors in the logs but it is still not pulling the email from WEBOEL23 so I tried renaming the logical file to Webemails in models/weboel23.rb. I also tried using ACT223.find_by(:email => $EMAL23 all of these seem to function without error but not pulling email not sure what would cause this there is valid data and I can connect to the table.

 

in the models/order.rb I am calling the mailer lie this: Mailer.deliver_order_distributor_approval_email($get_email, "Coastal Pet Online Ordering<noreply@coastalpet.com>", "DIST Approval-0 ", email_details) 



#6 Bob Kendall

Bob Kendall

    Signalman

  • Members
  • 18 posts

Posted 25 February 2014 - 03:53 PM

I also tried adding the following to models/weboel23.rb--

 

class Email_Approvals < ActiveRecord::Base   
establish_connection "as400_#{RAILS_ENV}"
  set_table_name "WEBEMAILS"  
  
  def self.weboel23
    @weboel23
   end
     
   def self.get_email(account0)
  @webemails = WEBEMAIL.EMAL23
  User.find_by(:email => @webemails) 
  end  
  
end
 
and then called it in models/order.rb:
Mailer.deliver_order_distributor_approval_email(@weboel23.get_email, "Coastal Pet Online Ordering<noreply@coastalpet.com>", "DIST Approval-0 ", email_details)
 
this generates NomethodError (undefined method 'get_email for nil:NilClass':)
 
Does this mean that it is not connecting to the logical file WEBEMAILS on the AS400? I assume it is connecting because it returns an ibm based error when it doesn't but I am not pulling the emails either.


#7 Bob Kendall

Bob Kendall

    Signalman

  • Members
  • 18 posts

Posted 25 February 2014 - 04:49 PM

Another question, should the class that I have above (models/weboel23.rb) be in mailer.rb instead?







Also tagged with one or more of these keywords: ruby1.9, rails3.2, AS400, Activerecord, instanceMethod

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users