Collection partial variable naming - new in edge rails 2

Posted by Slobodan Kovačević on July 07, 2008

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.

Share/Save/Bookmark

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. bruce balmer Mon, 21 Jul 2008 18:43:35 UTC

    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?

  2. bruce balmer Mon, 21 Jul 2008 19:14:20 UTC

    Cancel that. I had executed rake rails:freeze:edge but my version received was not up to date.

Comments