You’re not receiving notifications from this thread.
What is the best way to house view logic?
I have a view that is showing a list of steps. The steps are being pulled from the db with a status field.
There is a method that I've created that creates custom text based on the status, ie:
... some code to determine the custom string
I already have a ViewModel that is assembling the data and has an attribute called 'steps' that the view will use to list the steps, but I need to add the custom_text to each step.
Should I create a helper method and call from the view, or simply create a method in my ViewModel that loops through the steps and creates a new array with the added 'custom_text' attribute?
I was hoping to avoid helper methods since I'm trying to keep my views as codeless as possible, what is the best practice here?
Helper method with a case/switch statement would work well here.
somethng along the lines of
Thanks Jack, so you would use a helper like:
Text: <%= custom_text(status) %>
The only con I see with this approach is now you have a ViewModel and a helper file vs keeping all of the logic in the ViewModel.
If that's the best convention though I'll go with it!
I think Jacks answer is the more railsy way of doing this, so if you're worried about convention then that's probably your best bet.
However, you're already stepping outside the normal rails convention space by utilizing a view model pattern, so really your idea of making another method inside your view model probably fits better with your design.
Just my thoughts FWIW, good luck!