Say I have to Models, Project and Creator, related to each other such
that @project.creator is valid. Creator has two fields, first_name
and last_name, for the creator’s name. Assuming that I want a quick
way to display the creator’s name as “last_name, first_name” inside
the view, which is the best approach (efficiency, the Rails way, etc.)
Here are the approached I’ve come up with…
A) Create a method in the Creator class called commified_name and use
@project.creator.commified_name in the view. This seems like a good
option. It’s DRY and fits the rest of the mold for @project.xyz in
the view, but I think following MVC the model is not meant for
[self.last_name, self.first_name].join(’, ')
B) Do the join inside the view. Probably the worst of the options
since it allows for variations in how the name is displayed.
C) Create a method in the Creator Helper called commified_name and use
commified_name in the view. I believe this is the best answer since
formatting of information that goes in the View belongs in a Helper,
right? I just find that A feels more right to me.
') if @project
If C (or A) is the best answer, is this a good way to accomplish what
I’m after. Thanks in advance.