Skip to content

Instantly share code, notes, and snippets.

@dreamr
Created September 4, 2013 19:50
Show Gist options
  • Save dreamr/6441970 to your computer and use it in GitHub Desktop.
Save dreamr/6441970 to your computer and use it in GitHub Desktop.
def feeds_counts
@result = []
current_user.feeds.each do |feed|
@result << {
id: feed.id,
title: feed.title,
count: feed.post_count_since_last_read
}
end
respond_to do |format|
format.json { render json: @result }
end
end
# feed_params = [
# {id: 1, title: 'test 1', post_count_since_last_read: 2},
# {id: 2, title: 'test 2', post_count_since_last_read: 23}
# ]
# feeds = feed_params.map {|p| Feed.new(p) }
require 'ostruct'
class Feed < OpenStruct
include Enumerable
def to_feed_count_json
{
id: id, title: title,
count: post_count_since_last_read
}
end
end
@result = feeds.map(&:to_feed_count_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment