Access a instance method from other model in ruby on rails? -
i have user model in application. want replace user model coding 2 categories employ.rb , customer.rb under module users, avoid more number of codes in single model. want access method send_mail in customer.rb after user created.
user.rb
after_create:send_msg_on_order def send_msg_on_order users::customer.send_mail end users/customer.rb
def send_mail mailer.send_mail_to_customer.deliver end and getting undefined method `send_mail' users::customer:module error.
you have defined send_mail method instance method calling class method. either create class method or create instance of customer model , phone call it.
making method class method:
def self.send_mail mailer.send_mail_to_customer.deliver end if wish maintain instance method, phone call this:
after_create:send_msg_on_order def send_msg_on_order users::customer.new.send_mail end hth
ruby-on-rails ruby
No comments:
Post a Comment