Results 1 to 1 of 1
Sep 13, 2011, 07:16 #1
- Join Date
- Dec 2004
- 0 Post(s)
- 0 Thread(s)
optional argument in helper method
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"
if day.wday == 6
class_string << "week_end"
if day.to_s.eql? DateTime.now.strftime('%Y-%m-%d')
class_string << "current_date"
if day.to_s == project.first.start_date.to_s
class_string << "project_start"
if day.to_s == project.first.due_date.to_s
class_string << "project_end"
return class_string.join(" ")
your brain reacts in the same way whether you are
looking at something or thinking about it...