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 8240157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:23:31+00:00 2026-06-07T20:23:31+00:00

I have a partial that I’m rendering twice on the same page, but in

  • 0

I have a partial that I’m rendering twice on the same page, but in two different locations (one is shown during standard layout, one is shown during mobile/tablet layout).

The partial is rendered exactly the same in both places, so I’d like to speed it up by storing it as a variable if possible; the partial makes an API call each time, and the 2nd call is completely unnecessary since it’s a duplicate of the first API call.

Is there any way to store the HTML from the returned partial as a variable and then use that for both renders?

Edit: I’m hoping to do this without caching, as it is a very simple need and I’m looking to keep the codebase lean and readable. Is it possible to store the partial as a string variable and then reference that twice?

  • 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-06-07T20:23:32+00:00Added an answer on June 7, 2026 at 8:23 pm

    One option would be to use fragment caching. After you wrap the partial with a cache block, the second call should show the cached version of the first. For example:

    <% cache do %>
      <%= render(:partial => 'my_partial') %>
    <% end %>
    
    ... later in the same view ...
    
    <% cache do %>
      <%= render(:partial => 'my_partial') %>
    <% end %>
    

    To store the result of the render to a string, you could try the render_to_string method of AbstractController. The arguments are the same as for render.

    partial_string = render_to_string(:partial => 'my_partial')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a partial view that needs to get loaded between two div but
I have a partial view that is shared between two controllers and I'm trying
MVC newbie question re binders. Supposing I have two strongly typed partial actions that
I have a partial that I'd like to use in a layout but when
I have a partial view that I am using from 2 different forms. In
I have a partial that show a form into a page. As I submit
On a view, i have a partial view rendering an ajax form that allows
I have a partial view that is not rendering: The designer is telling me
I have a partial that I am using in different pages. I want to
I have a Partial view that I would like to use on 2 different

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.