Created
September 4, 2013 19:50
-
-
Save dreamr/6441970 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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