I have a view in which I have the same link 3 times (actual view is large):
%h1= link_to "Title", model_path(@model, :class => "lightbox")
= link_to "Check it out", model_path(@model, :class => "lightbox")
%footer= link_to "Last time", model_path(@model, :class => "lightbox")
That model_path(@model, :class => "lightbox") call, though fairly clean, can be made even leaner wrapping it in this (maybe you had some more options, so doing this was worthwhile):
def popup_model_path(model)
model_path(model, :class => "lightbox")
end
My question is, I am having to recalculate that path 3 times in a view. What is the preferred way of a) DRYing this up and b) optimizing performance?
I think setting variables at the top of the view might be a good idea here:
- path = model_path(@model, :class => "lightbox")
-# ... rest of view
It’s almost like mustache in the end then. What are your thoughts?
I really hate putting variables in the view. I would change your helper to
to “memoize” it, and just keep the three function calls.