In my view, let’s say I have something like this:
<%= f.text_field :name_first %>
and another time this:
<%= f.text_field :name_last %>
Instead of hard-coding the field names, I want to dynamically generate them using a view helper method.
def category_name
@contact_info.category.name
end
def return_field_name
category_lower = category_name.downcase
":name"+category_lower
end
So now my view should have something like this:
<%= f.text_field return_field_name %>
Write:
But if it will help you you should write only pure methods. IMHO it’s very good practice.