Collection partial variable naming - new in edge 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.

Share/Save/Bookmark


2 Responses to “Collection partial variable naming - new in edge rails”

  1. bruce balmer Says:

    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 Says:

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

Leave a Comment

Icebergist blog

Slobodan Kovacevic

Categories

Tags

Blogroll

Subscribe