I am getting a NoMethodError when trying to call my "not_coworker_friend" or "coworker_friend" method. I am working in Ruby MVC. This is my current code, As written it does not produce any errors:
class EmergencyTrip < ActiveRecord::Base
belongs_to :user
has_attached_file :receipt
validates_attachment_presence :receipt
validates_presence_of :trip_cost, :if => :not_coworker_friend
validates_presence_of :phone_of_person, :if => :coworker_friend
def not_coworker_friend
(self.ride_home_service == "co-worker/friend") ? false : true
end
def coworker_friend
(self.ride_home_service == "co-worker/friend") ? true : false
end
end
My objective is to only validate the receipt if "not_coworker_friend" == true.
Lines 5 & 6 should be:
...
has_attached_file :receipt, :if => :not_coworker_friend
validates_attachment_presence :receipt, :if => :not_coworker_friend
...
Adding the ":if => not_coworker_friend" to those lines generates a NoMethodError (undefined method `call' for :not_coworker_friend:Symbol):, even though there is no error thrown for lines 8 & 9. Why does this only selectively throw an error? And how can I correct this?
Proc.new ...