Reputation: 176
I'm really new to rails, working on someone else's code, and I'm stuck on the simplest thing!
I defined an instance method in the model but I can't seem to call it. I found a bunch of similar questions but nothing quite right.
For this question, Rails: Model instance method or helper method?, how would you then call full_name after defining it in the model? In the rails console User.first.first_name
returns the first user's first name but User.first.full_name
returns a undefined method error.
Upvotes: 2
Views: 2125
Reputation: 118299
It seems your were in the rails console before defining the method inside the model. That's making the the new method to your model unavailable in the rails console. So, just do reload!
(reloads the environment) and try the same again, and this time you will have the access to the method.
Upvotes: 3