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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:02:09+00:00 2026-05-23T17:02:09+00:00

I have a Podcast model with one attribute called :url . A typical :url

  • 0

I have a Podcast model with one attribute called :url.

A typical :url takes the following form: http://api.mixcloud.com/alivefrommaryhill/jazzcast/ and returns a JSON file

Using hashie and httparty, we can write a method (called get_json) that uses this URL to create a hash from the JSON that it links to:

class Podcast < ActiveRecord::Base
  attr_accessible :url  

  def get_json
    Hashie::Mash.new HTTParty.get("#{self.url}")
  end   
end

We can then use get_json in our views to style and display the JSON:

#/views/podcasts/index.html.haml
- for podcast in @podcasts  
  = link_to podcast.get_json.name, podcast_path(podcast)
  = podcast.get_json.description
  = image_tag podcast.get_json.pictures.medium

As you can see, each podcast calls get_json three times. I’ve got 21 podcasts and don’t want to call this method more than once per visit since it connects to an external web-service which is very time-consuming. How can I minimize the number of times this method is called and speed things up?

Perhaps I should be doing more in my controller instead of calling the method from my view?

def index
  @podcasts = Podcast.all
end

Any help 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-23T17:02:10+00:00Added an answer on May 23, 2026 at 5:02 pm

    Well, the easiest fix for now would be to save the result of podcast.get_json in a local variable. That’d cut it down to once per podcast.

    If you want to further reduce the number of calls, you’d have to figure a way to batch all your requests. I don’t know if that site’s API will let you do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my feed generation code I have things like: XNamespace itunesNS = http://www.itunes.com/dtds/podcast-1.0.dtd; feed.ElementExtensions.Add(
In StackOverflow podcast no. 19 , Joe describe Fogcreek's decision to have one database
On the SO blog and podcast Joel and Jeff have been discussing the, often
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have a problem similar to the on in this weeks podcast. We have
I was listening to a podcast recently (may have been SO - can't remember)
I have a collection of custom objects (Podcast) in an array. When I use
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
I have a script that appends some rows to a table. One of the

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.