Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5962453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:06:27+00:00 2026-05-22T19:06:27+00:00

Currently I’m using: <% @items.each do |item| %> <li class=list-item> <%= render :partial =>

  • 0

Currently I’m using:

<% @items.each do |item| %>
  <li class="list-item">
    <%= render :partial => '/widgets/vertical_widget',
               :object => item %>
  </li>
<% end %>

to render about 20 items on a page (there’s also another 20 of a different widget on the same page).

When I look at my server logs it’s showing ~400ms per widget render, totaling out to ~20k ms for the page. From what I’ve read using :colletion instead of a loop with :object should help to improve those times however I’m not sure how I can wrap each instance of the widget in an LI if I use :collection. Not ever place the widget is used on the site is in a list so it doesn’t make sense to include the LI in the widget code.

I could include the widget code directly in the loop rather than in a partial however I don’t want to have to make code updates in multiple places.

Any other ideas to improve performance would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:06:28+00:00Added an answer on May 22, 2026 at 7:06 pm

    Give content_tag a try:

    #some_file.html.erb
    
    <ul>
    <%= render :partial => 'widgets/vertical_widget', 
               :collection => @items, 
               :locals => { :wrap_in => :li } %>
    </ul>
    
    
    
    #/widgets/vertical_widget.html.erb
    
    #First, render and capture the content once.
    <% @rendered_content = capture do %>
      #render the item here
    <% end %>
    
    #Next, decide if the content rendered above should be wrapped in a tag or not
    #If the "wrap_in" variable was passed-in and it is not nil/empty, then use that
    #value for the tag; else do not wrap the content in a tag
    <% if defined?(wrap_in) && !wrap_in.blank? %>
      <%= content_tag wrap_in do %>
        <%= @rendered_content %>
      <% end %>
    <% else %>
        <%= @rendered_content %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, i'm sorting a list using LINQ to objects, then doing a ToList() on
Currently, I am developing a product that does fairly intensive calculations using MS SQL
Currently my AJAX is working like this: index.php <a href='one.php' class='ajax'>One</a> <div id=workspace>workspace</div> one.php
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
Currently we have a large DataTable (~152k rows) and are doing a for each
Currently, db4o does not allow indexing on the contents of collections. What object databases
Currently in my webpage i load images to the ListView object as follows... <ContentTemplate>
Currently I am using a pretty basic function to pre-load images: function preload(arrayOfImages) {
Currently I am trying to render a .obj model that I loaded into vectors.
Currently I have a service that downloads about 500 records of somewhat complex data,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.