It displays the full name in the selection box options.
But if I try to go <%=h @user.full_name %> I get an error saying
“private method `full_name’ called for <…>”
Do I need write a duplicate method in the user controller?
def full_name
first_name + " " + last_name
end
What goes on with the name space issue if I made the two slightly
different?
Would the collection_for_select start looking at the controller action
instead?
I suppose I don’t really have a problem but duplicating the little
method strikes me as a bit slovenly. Would putting it in the helper
area change anything?
that probably uses send to call the method (which doesn’t care about
private methods)
maybe i don’t want that code in the model even though it works?
Can I ask the obvious question: is the full_name method private?
Fred
No it will work if I made a controller method.
I was wondering if I really needed a duplicate full_name method in the
controller if I had one in the model. Perhaps I should just scrap the
one in the model and just use one in the controller? Seems a shame to
have two of them. Would you put that sort of thing in the helper file?
No, you need to look at Fred’s question. That method is simply an
attribute method and should not be protected or private. If it is not,
it should work fine anywhere your object exists.
-Bill
Thank you both for staying with me.
I had an error in my model and had my method AFTER the “end” to the
class. (the end was after the validations then I put the method below
that! )
I am sorry to waste your time but it was an important thing I was on the
verge of getting quite wrong. Now that it works, it looks like the model
is a fine place to put model object specific little data manipulations
things like that. I was on the verge of loading them into the wrong
places.
Thanks again for forcing me to take the 10th pass that caught my
mistake.
No, you need to look at Fred’s question. That method is simply an
attribute method and should not be protected or private. If it is not,
it should work fine anywhere your object exists.
-Bill
Tom N. wrote:
Fred
No it will work if I made a controller method.
I was wondering if I really needed a duplicate full_name method in the
controller if I had one in the model. Perhaps I should just scrap the
one in the model and just use one in the controller? Seems a shame to
have two of them. Would you put that sort of thing in the helper file?
No problem, you aren’t wasting my time. We all overlook things from time
to time. As far as where to put this, you are correct. Anything that
changes the interface of the model class should go into the model, or a
module if it’s going to be mixed in to multiple models.
-Bill
Tom N. wrote:
Thanks again for forcing me to take the 10th pass that caught my
mistake.
Tom
–
Sincerely,
William P.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.