I’m having a heard time properly creating a collection according the to the Rails Guide documentation and have had to do a workaround for months.
The Problem In Detail
I have a simple model (goal) ith only one attribute (copy) ; It’s partial is straight-forward
#_goal.html.haml %li= goal.copy
Based on the Rails documentation, it should be as simple as the following to render a collection view (with or without decorator/helper encapsulation)
#show.html.haml of the model - if @goals.any? = render 'goals/goal', collection: @goals, as: :goal - else = "This Project doesn't have goals, or it wasn't applicable for this particular project to have goals."
For some reason, this has not worked for me ever.
What I’ve had to do instead
Instead, I have had to do the following
#shared/goal_list.html.haml %ul.large-12.columns = render object.goals
And then the following with the model
- if @goals.any? = render 'shared/goal_list', object: @project - else = "This project doesn't have goals, or it wasn't applicable for this particular project to have goals." ## While this works, it's a n+1 problem :/
With this in mind, what am I doing wrong to the extend I can’t take advantage of the collection syntax for partials?