How do i style a JSON feed in my view?

Posted by stephenmurdoch on Stack Overflow See other posts from Stack Overflow or by stephenmurdoch
Published on 2011-01-12T01:13:05Z Indexed on 2011/01/12 3:53 UTC
Read the original article Hit count: 264

Filed under:
|

My rails app gets the following JSON feed from mixcloud and sticks the results into my index page

At the moment when I do this, the entire contents of my feed are displayed unformatted in one big blob of scary looking text (without the curly JSON brackets)

I only want to display specific values from the feed in the view.

From the feed in question lets say for simplicity that I just wanted to display all values with a key of "url"

In case I'm doing something wrong here's my code:

# podcast controller
def index
  # I'm using a class method to get the feed
  @feed = Podcast.feed
end

# podcast model
def self.feed
  feed = JSON.parse(open("http://api.mixcloud.com/alivefrommaryhill/feed").read)
end

# index.html.haml
.feed
  = @feed

I can't figure out how to style the results and display only certain items from the feed. Is my approach wrong?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about JSON