简体   繁体   中英

How can I call a class method from Model rails

app/services/mail_service

class MailService
 def subscribe
  code
 end 
end

User Model

class User < ActiveRecord::Base
 after_create :user_subscribe
 def user_subscribe
    Services::MailService.new
 end
end

It shows error like uninitialized constant Services

您不必编写服务,只需编写:-

MailService.new

Try this

require 'MailService.rb'
class User < ActiveRecord::Base
 after_create :user_subscribe
 def user_subscribe
    MailService.new
 end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM