Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLarry Lee
1,386 PointsNoMethodError in Statuses#index undefined method `round' for "ago":String
I'm getting the following error when following along with this tutorial and I'm not sure what I might be doing wrong. Any help would be appreciated. Thanks.
NoMethodError in Statuses#index
Showing /Users/larrylee/Documents/juntbook/app/views/statuses/index.html.erb where line #10 raised:
undefined method `round' for "ago":String Extracted source (around line #10):
7: <strong><%= status.name %></strong> 8: <p><%= status.content %></p> 9: <div class="meta"> 10: <%= link_to time_ago_in_words (status.created_at) + "ago", status %> 11: <span class="admin"> | 12: <%= link_to "Edit", edit_status_path(status) %> | 13: <%= link_to "Delete", status, method: :delete, data: {confirm: "Are you sure you want to delete this status?"} %>
3 Answers
dan schmidt
2,576 PointsWell, somewhere in the code, rails is attempting to call "ago".round
and is throwing a NoMethodError
as it should. My rails is pretty rusty, but my first guess is that it is failing to parse your link_to
invocation correctly. Trying adding parens around the parameters like so:
link_to( time_ago_in_words( status.created_at ).concat( "ago" ), status )
At least, I think that is what you're trying to call there, lol. It's a lot packed into that erb tag.
Larry Lee
1,386 PointsThanks Dan, that worked. I know you say it should have given me an error based on my code which is weird because I typed this exactly as it was shown in the Ruby on Rails tutorial. I'm not sure, maybe it has something to do with the version of Ruby/Rails I'm using? I upgraded both after starting the tutorial. I've got to research to see where I went wrong. Thanks again!
dan schmidt
2,576 PointsYea, I didn't mean to infer it was some huge mistake on your part and yea, it is very well likely due to different versions of rails being used.
The thing is ruby has a bunch of optional syntax in certain contexts and a lot of over loaded methods. If you are coding in the "haiku" style by leaving off parens and you are getting confusing errors, the first thing you should always try is using parens instead.
dan schmidt
2,576 PointsAnd what I meant by saying that it should throw an error is not based on your code, but based on the fact that either erb
or rails
was calling the round
method on the string "ago"
. String objects do not respond to the method round
so they correctly should throw the NoMethodError
Larry Lee
1,386 PointsWell that makes sense. I'm new to ruby and rails so this was helpful!