Are partial custom reference names possible?

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

Store the reference name as a variable and just do:

<%= render :partial => custom_var %>

On Dec 18, 2007 9:20 AM, Chris O. [email protected]
wrote:

I don’t like the way that to make reference to a single member within
Thanks

Posted via http://www.ruby-forum.com/.

–
Ryan B.

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. [email protected]
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.

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. [email protected]
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/.

–
Ryan B.

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. [email protected]
wrote:

<%= member_pic.phone_number %> that I have 3 different partials for a member. >

–
Ryan B.

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

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? :slight_smile: I have always done it that way. That will save me some
typing.

Thanks for the help.