Today’s lesson (for me, a Rails noob :D) is about how to pass variables to Rails partials.
I kept getting error when I tried to pass a variable to a partial with this method:
<%= render :partial => 'admin/publication_transactions/index', :publication_transactions => @publication_transactions %>
It turned out that when I use the :partial key, I need to wrap the variable to be passed inside a hash named :locals. Meanwhile, if I want to pass the variable without :locals hash, I must pass the path as a string instead of using the :partial key. So the correct codes are either this:
<%= render 'admin/publication_transactions/index', :publication_transactions => @publication_transactions %>
or this:
<%= render :partial => 'admin/publication_transactions/index', :locals => { :publication_transactions => @publication_transactions } %>
Thanks to xinuc for pointing out my mistake 🙂