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?
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.
精彩评论