you're reading...

How to implement “show more” and “show less” using a hidden counter when rendering a collection

While rendering a collection, I wanted to hide some items with higher indexes (and show them when clicking on “Show more”). But there is no way to tell the index when rendering :collection => @items. Then I came across this posting:

Render partial with collection has hidden counter

Now, when rendering

    <%= render :partial => 'item', :collection => @items %>

I can have the partial where only 3 items are shown:

<li style="<%= (item_counter + 1 > 3) ? 'display:none' : '')">item.name</li>

About RailsBlogger

I'm a Software Developer with over 10 years of experience, Java and Ruby on Rails.


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

ip tracing
%d bloggers like this: