如何从Model rails调用类方法

时间:2013-10-17 05:52:30

标签: ruby-on-rails methods model

应用程序/服务/ mail_service

class MailService
 def subscribe
  code
 end 
end

用户模型

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

显示uninitialized constant Services

之类的错误

2 个答案:

答案 0 :(得分:0)

你不必写服务只写: -

MailService.new

答案 1 :(得分:0)

试试这个

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