Collection partial variable naming - new in edge rails
- Posted by Slobodan Kovačević on July 7th, 2008 filed in Ruby and Rails
One thing that always annoyed me when rendering collection partials is that a local var in partial is named same as a partial template name. So, to go around this I always created another local variable in partial and gave it a more meaningful name.
No longer… As the Ryan says from now on in the Edge Rails you can specify the name of the local variable in which each collection element will be exposed within a partial. You will can do this:
render :partial => 'employees', :collection => @workers, :as => :person
It’s a simple thing, but it’s just one of the things that bugged me. I am glad it’s gone now.
July 21st, 2008 at 6:43 pm
I was reading Ryan’s scraps and tried it. I am on edge, it does not work for me. Do you know something I don’t? The full partial name works for the name of my variable, :as seems to not be working even slightly.
=render :partial => ’shared/list_bullet’, :collection => @lists, :as => :list
When I try to use list.name in my view I am told that no such variable exists.
Any clues?
July 21st, 2008 at 7:14 pm
Cancel that. I had executed rake rails:freeze:edge but my version received was not up to date.