#The Problem
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."
- 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?
@joelq, @patrikbona: Thanks to the both of you on helping me improve on either approach; I was aware of the convenience of passing in @goals, but somehow made things hard than they needed to be on this occasion.
It was really handy to be informed of render method way of taking options and extra options the way it does than I realized from the documentation; ‘string’ not necessarily passing that.