参数数量错误(3个为2)

时间:2016-04-11 23:26:42

标签: ruby-on-rails ruby

这是第一次在rails中遇到这个错误,我真的不知道它来自哪里是函数实现:

   def self.send (sender,recivers,content)
            recivers.each do |reciver|
                @notification = Notification.new
                @notification.sender= sender
                @notification.user = reciver
                @notification.body = content 
                @notification.save
            end 

    end 

以下是我如何称呼它:

def after_create(announcment)
    instructor_id = announcment.course.instructor_id
    sender = User.find_by_id(instructor_id)
    students = announcment.course.users
    body = announcment.announcment
    coures_name = announcment.course.name 
    Notification.send(sender,students,body)
    UserMailer.notify_students_course(students,coures_name)
end

1 个答案:

答案 0 :(得分:2)

send是来自Object类的Ruby方法(因此每个类都继承它),它调用以第一个参数命名的方法,并参数给予send的其余参数。同样在RoR中它是reserverd word

最好不要覆盖它,因为它可能会变得混乱。