我在我的event.rb模型中有兩個私有方法,我希望這兩個方法應該在我的事件控制器中的兩個不同的操作上調用。在rails上使用私有方法
event.rb
private
def create_notification_on_accept
self.notifications.create(action_type: "Accept", actor_id: participant.id,
user_id: user_id)
end
def create_notification_on_reject
self.notifications.create(action_type: "Reject", actor_id: participant.id,
user_id: user_id)
end
events_controller.rb
def accept_invitation
@participants.where(user_id: current_user.id).update_all(is_attending: true)
render "update"
end
def reject_invitation
@participants.where(user_id: current_user.id).update_all(is_attending: false)
render "update"
end
我怎麼能說我的控制器這兩個私人注資方式?
任何建議是有幫助的。
你爲什麼不讓他們公開? – Santhosh
「私有方法只能由同一類內或同一模塊內的方法調用」。這是私人方法的基本定義。 – shivam
Santosh,如果我將它們公開,我可以直接從控制器操作訪問它們嗎? – Packer