Passing an object


#1

I dreated an app called employee using scaffolding. Changed the list
view to incorporate a helper to display date as follows:

Listing employees

<% for column in Employee.list_columns %> <% end %>

<% for employee in @employees %>

"> <% for column in Employee.list_columns %> <% end %> <% end %>
<%= column.human_name %>
<%=h format_date(column.name,employee) %><%= link_to 'Show', :action => 'show', :id => employee %> <%= link_to 'Edit', :action => 'edit', :id => employee %> <%= link_to 'Destroy', { :action => 'destroy', :id => employee }, :confirm => 'Are you sure?', :method =>$

<%= link_to ‘Previous page’, { :page => @employee_pages.current.previous
} if @employee_pages.current.previous %>
<%= link_to ‘Next page’, { :page => @employee_pages.current.next } if
@employee_pages.current.next %>


<%= link_to ‘New employee’, :action => ‘new’ %>

The helper is in application_helper.rb as follows:

Methods added to this helper will be available to all templates in the

application.
module ApplicationHelper
def format_date(col_name,date_object)
if col_name.include? “date”
date_object.send(col_name).strftime(’%m/%d/%Y’)
else
date_object.send(col_name)
end
end
end

Here’s the rub, I want to use the helper in the show view (something
like the following):

<% for column in Employee.content_columns %>

  <b><%= column.human_name %>:</b> <%= format_date(column.name,

@employee) %>

<% end %>

<%= link_to ‘Edit’, :action => ‘edit’, :id => @employee %> |
<%= link_to ‘Back’, :action => ‘list’ %>

But, I get this error:

You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.strftime

We’ve tried eveything that we can think of without success. What gives?

I appreciate your help and any suggestions regarding my problem or
suggestions regarding coding that you would care to make. Learning to
think the way in that Rails (and Ruby) work is certainly turning into an
experience.

Thanks again,

rB
Randy