为什么不能在update_message_business_id
下使用private
方法?
class Payment < ApplicationRecord
...
def self.last_payment_gathering_information(customer_thread_id, employee_user_id, business_id)
payment = Payment.joins(:message).where("messages.customer_thread_id = ?", customer_thread_id)
.where("messages.employee_user_id = ?", employee_user_id)
.where(state: :gathering_information)
.order(id: :desc).first
payment.update_message_business_id(business_id) unless payment.nil?
payment
end
private
def update_message_business_id(business_setting_id)
business_setting = BusinessSetting.find_by_business_id(business_setting_id)
self.message.business_setting = business_setting
self.message.save
end
end
# => NoMethodError (private method `update_message_business_id' called for Payment:0x00007faac24548d0*
答案 0 :(得分:3)
直接,这是因为你用显式接收器调用这个方法,而你在Ruby中做不到。
要扩展此答案,您无法在此上下文中真正执行此私有方法调用,因为self
中的last_payment_gathering_information
(始终为默认接收方)指的是Payment
类,不是Payment
实例(具有update_message_business_id
私有方法)。