Reputation: 2028
I've been doing some testing in a simple Rails app.
In my controller, I assign an instance variable like this:
@user = User.last
This is strictly for testing — I have no good reason to pull the last user in this way.
In my view, I use the pluralize method to report the number of users. Of course, since I'm using User.last
, there is only one.
In the view, the code is <%= pluralize(@user.size, 'User') %>
.
When it runs the application throws a NoMethodError for size
.
You would think that size would report 1 in this case but, for some reason, it doesn't.
I'm curious why?
Upvotes: 0
Views: 61
Reputation: 24815
The title is a false claim. pluralize
is just a helper, it doesn't matter where you use it.
In your case, @user is a single record. It doesn't have size
method. That's true. So the error is expected, nothing wrong.
Upvotes: 1