I’ve got a helper method to add classes in my view, last argument is optional. Right now I’m testing for the optional argument with “if (defined?(project.first)).nil?”, but it’s not working as expected…*it’s always returning false, even when I KNOW there is a hash getting passed to it.
Also, another thing is my record that I submit as the optional argument is getting turned into an Array. If I remove the .nil? test then it works when the optional argument is present but fails when not present.
Anyone see something I’m doing wrong?
@project = Project.find(params[:id])
<%= calendar_classes(day, @project) %>
def calendar_classes(day, *project)
class_string = []
if day.wday == 0
class_string << "week_start"
end
if day.wday == 6
class_string << "week_end"
end
if day.to_s.eql? DateTime.now.strftime('%Y-%m-%d')
class_string << "current_date"
end
if (defined?(project.first)).nil?
if day.to_s == project.first.start_date.to_s
class_string << "project_start"
end
if day.to_s == project.first.due_date.to_s
class_string << "project_end"
end
end
return class_string.join(" ")
end