简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM