# Are partial custom reference names possible?

**URL:** <https://www.ruby-forum.com/t/are-partial-custom-reference-names-possible/123459>\
**Category:** Rails\
**Created:** [December 17, 2007, 11:50pm UTC](https://www.ruby-forum.com/t/are-partial-custom-reference-names-possible/123459 "2007-12-17T23:50:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [December 17, 2007, 11:50pm UTC](https://www.ruby-forum.com/t/are-partial-custom-reference-names-possible/123459/1 "2007-12-17T23:50:52Z")

</div>

I have a couple different partials for members, to which each have names  
that somewhat describe what the partial is:

ex member\_pic  
\<%= render :partial =\> “admin/members/member\_pic”, :collection =\>  
@members %\>

Which shows the members pic along with their details.

I don’t like the way that to make reference to a single member within  
the @members collection inside the partial I have to use the partial  
name, ex member\_pic.full\_name. I have other cases where it can be  
confusing.

I figure there must be a way around this, since this Rails :), but I  
haven’t been able to find out how.

…if you are just rendering a single object you could probably pass it  
in through the locals, but there must be a better way.

Thanks

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [December 17, 2007, 11:56pm UTC](https://www.ruby-forum.com/t/are-partial-custom-reference-names-possible/123459/2 "2007-12-17T23:56:29Z")

</div>

Store the reference name as a variable and just do:

\<%= render :partial =\> custom\_var %\>

On Dec 18, 2007 9:20 AM, Chris O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## I don’t like the way that to make reference to a single member within Thanks
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [December 18, 2007, 12:05am UTC](https://www.ruby-forum.com/t/are-partial-custom-reference-names-possible/123459/3 "2007-12-18T00:05:13Z")

</div>

Ryan B. wrote:

> Store the reference name as a variable and just do:
> 
> \<%= render :partial =\> custom\_var %\>
> 
> On Dec 18, 2007 9:20 AM, Chris O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:

I am note sure how that will change the reference to the  
object/collection within the partial?

I know if you have a \_member.html.erb partial you can do like you  
mentioned:  
\<%= render :partial =\> @member %\>

but that then calls on the \_member.html.erb partial.

In my case I have a partial called \_member\_pic.html.erb, but I have a  
variable of @members that is to be passed into it. I could instead  
create a collection called @member\_pics, but that would lead to further  
confusion and wouldn’t change how the reference is made within the  
partial file.

Or at least I think :), if not please give me some more details to what  
you meant.

Thanks.

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [December 18, 2007, 1:01am UTC](https://www.ruby-forum.com/t/are-partial-custom-reference-names-possible/123459/4 "2007-12-18T01:01:31Z")

</div>

I think we’re both confused.

What are you trying to do again? Could you elaborate?

On Dec 18, 2007 9:35 AM, Chris O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am note sure how that will change the reference to the  
> create a collection called @member\_pics, but that would lead to further  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [December 18, 2007, 1:36am UTC](https://www.ruby-forum.com/t/are-partial-custom-reference-names-possible/123459/5 "2007-12-18T01:36:05Z")

</div>

Oh I see what you mean, I think. You want to see the local name that’s  
used  
for the collection? You can’t do this.

Also you’re passing in an instance variable as a local, why? The  
instance  
will be available in the partial.

On Dec 18, 2007 10:50 AM, Chris O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> \<%= member\_pic.phone\_number %\> that I have 3 different partials for a member. \>

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [December 18, 2007, 1:20am UTC](https://www.ruby-forum.com/t/are-partial-custom-reference-names-possible/123459/6 "2007-12-18T01:20:28Z")

</div>

🙂 I guess I didn’t make it very clear. The issue that I have is a  
making reference the object/collection within the partial ex.

##\_member\_pic.html

| \<%= image\_tag member\_pic.photo.public\_filename(:thumb) %\> |
| \<%= member\_pic.full\_name %\> |
| \<%= mail\_to member\_pic.email %\> |
| \<%= member\_pic.phone\_number %\> |
| \<%= link\_to "Remove", admin\_group\_member\_url(group, member\_pic.group\_members.first.id), :method =\> :delete %\> |

\<%= render :partial =\> “admin/members/member\_pic”, :collection =\>  
@members, :locals =\> {:group =\> @group} %\>

As you can see I have to call member\_pic.full\_name within the partial  
seeing as that is the name of the partial. The reason for this name is  
that I have 3 different partials for a member.

I was just wondering if there is a way to better control the reference  
that is used within the partial.

Thanks for the help.

BTW the table is needed 🙂

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [December 18, 2007, 1:39am UTC](https://www.ruby-forum.com/t/are-partial-custom-reference-names-possible/123459/7 "2007-12-18T01:39:26Z")

</div>

Ryan B. wrote:

> Oh I see what you mean, I think. You want to see the local name that’s  
> used  
> for the collection? You can’t do this.

That is sad to hear

> Also you’re passing in an instance variable as a local, why? The  
> instance  
> will be available in the partial.

Oh really? 🙂 I have always done it that way. That will save me some  
typing.

Thanks for the help.
