When creating a model function does it get seen to the controller?
I have a model present and i have the following function
before_create :check_exists
attr_accessible :customer_id, :event_id
#RELATIONSHIP
belongs_to :customer
belongs_to :event
private
def check_exists
present = Present.find_or_create_by_customer_id_and_event_id(:customer.id => current_customer.id, :event_id => self.event_id)
end
How do I know that self.event_id is being use properly, how do i call this resource properly
Yes, the method can be accessed through controllers.
:customer_id
and :event_id
are supposed to be both properties of the model instance, so they will be used accordingly within your method. All you have to do is call check_exists
from any Present
instance (not the Present
class, for this is not declared as static method).
Luck.
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.