Reputation: 1123
To break down my app quickly: I have a songs, comments, and users model. User's can upload songs, and make comments.
I seem to be getting "undefined method `strftime' for nil:NilClass" error after submitting (creating) a song. If you go to show#songs.html.erb you'll see the comments code below. I've looked into how Ryan Bates does his comments and my code is identical. Not sure why strftime is't working. Please advise :)
Note: for what it's worth I'm running rails 4
Full error msg:
NoMethodError in Songs#show
Showing /Users/apane/Downloads/leap/app/views/songs/show.html.erb where line #34 raised:
undefined method `strftime' for nil:NilClass
Extracted source (around line #34):
<% for comment in @song.comments %>
<div class="comment">
<strong><%= link_to_unless comment.site_url.blank?, h(comment.author_name), h(comment.site_url) %></strong>
<em>on <%= comment.created_at.strftime('%b %d, %Y at %H:%M') %></em>
<%=simple_format comment.content %>
<p>
<% if can? :update, comment %>
Upvotes: 0
Views: 2516
Reputation: 1657
The comment.created_at is nil
- this is your problem.
It is probably because you have created the comment but didn't save it yet
.
The created_at field will be filled only upon save.
Upvotes: 3