Matthew Berman
Matthew Berman

Reputation: 8631

How do I render two different partials with the same name?

I have

render @users

in my users view. It renders the @users in a nicely formatted way that I specified in _user.html.erb. I am now trying to do this:

render @attendees

which is a hash of users. I am trying to render this in my events view (a different view). The problem is that I want to render @attendees differently than @users but it always seems to use the _user.html.erb to render. How do I specify a different rendering?

Upvotes: 0

Views: 294

Answers (1)

theIV
theIV

Reputation: 25774

As far as I'm aware, you can't use the convenience of render @attendees to render a different partial than _user since @attendees are actually User objects. Rails uses the class to figure out what partial to render when using this condensed format.

What you can do is render :partial => 'users/attendees', :collection => @attendees, assuming you have a partial users/_attendees.html.erb. If you don't want to throw that around everywhere, wrap it in a helper.

Upvotes: 4

Related Questions