Skip to content

Instantly share code, notes, and snippets.

@tomafro
Created February 24, 2010 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomafro/313277 to your computer and use it in GitHub Desktop.
Save tomafro/313277 to your computer and use it in GitHub Desktop.
class Message
extend ActiveModel::Naming
include ActiveModel::Serializers::Xml
include ActiveModel::Serializers::JSON
def self.for_subscriber(subscriber_id)
# nasty!
5.times.collect { Message.new }
end
def attributes
{'id' => id, 'content' => content}
end
def content
Faker::Lorem.sentences(1 + rand(4)).join(" ")
end
end
class SubscriberMessagesController < ApplicationController
respond_to :json, :xml
def index
respond_with Message.for_subscriber(params[:subscriber_id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment