Rails 3.0.2
Ruby 1.9.3
Im currently trying to have a view’s instance variable respond to the
call ‘holiday?’ with a boolean. i cant put it in a model’s class
definition, since i use several classes that contain dates.
it works if I add the following definition to environment.rb:
class String
def holiday? # on timestamp as string
if Holiday.where(date: Date.parse(self)).any?
true
else
false
end
end
end
now i can do this in my view:
<% if raw.timestamp.holiday? %>
thats nice and all, but its really seems to be the wrong way to do this,
not least because i have to restart the rails server to see changes to
the method. i tried it with the following definition, but it didnt work:
module ApplicationHelper
def holiday? # on timestamp as string
if Holiday.where(date: Date.parse(self)).any?
true
else
false
end
end
end
(i also tried it with self.holiday?)
Does anyone have a tip on how to go about this?