Strftime function on a nil object. Undefined strftime method? (SOLUTION)

28 Jan

In ruby, if you are using strftime to convert a numbered date into wordy type….

And once a value is NIL… an ERROR will occur.

 

To fix this, use the try method!

http://api.rubyonrails.org/classes/Object.html#method-i-try

 

Example, as a view:

 

<td><%= project.pre_procurement_conference.try(:strftime,”%B %d, %Y”) %></td>
<td><%= project.posting_advertisement.try(:strftime,”%B %d, %Y”)%></td>
<td><%= project.pre_bid_conference.try(:strftime,”%B %d, %Y”)%></td>
<td><%= project.submission_receipt_of_bids.try(:strftime,”%B %d, %Y”) %></td>
<td><%= project.bid_evaluation.try(:strftime,”%B %d, %Y”) %></td>
<td><%= project.post_qualification.try(:strftime,”%B %d, %Y”) %></td>
<td><%= project.award_of_contract.try(:strftime,”%B %d, %Y”) %></td>

 

 

That’s all. Hope it helps!

About these ads

2 Responses to “Strftime function on a nil object. Undefined strftime method? (SOLUTION)”

  1. jeremejazz February 5, 2013 at 6:01 am #

    hello nice help :) wanna join codersfriend? You can also post ur snippets using the code highlighter feature :)
    as of now, we don’t have ruby yet so I would be happy if you would be there
    http://www.codersfriend.net/ :)

    • Xiruki Tepe February 6, 2013 at 1:07 am #

      Hi sure. let me join whenever I’m free to.

Speak out dude!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 422 other followers

%d bloggers like this: