added custom as_json methods to models
This commit is contained in:
parent
de8450c7c5
commit
5e34506df6
6 changed files with 42 additions and 4 deletions
|
|
@ -20,6 +20,8 @@ class PeopleController < ApplicationController
|
|||
|
||||
@latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last
|
||||
@post_count = @posts.count
|
||||
|
||||
respond_with @person
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class UsersController < ApplicationController
|
|||
before_filter :authenticate_user!, :except => [:new, :create]
|
||||
|
||||
respond_to :html
|
||||
respond_to :json, :only => [:index, :show]
|
||||
respond_to :json, :only => :show
|
||||
|
||||
def show
|
||||
@user = User.find_by_id params[:id]
|
||||
|
|
|
|||
|
|
@ -27,9 +27,11 @@ class Group
|
|||
|
||||
def as_json(opts = {})
|
||||
{
|
||||
"name" => self.name,
|
||||
"people" => self.people.each{|person| person.as_json},
|
||||
"posts" => self.posts.each {|post| post.as_json },
|
||||
:group => {
|
||||
:name => self.name,
|
||||
:people => self.people.each{|person| person.as_json},
|
||||
:posts => self.posts.each {|post| post.as_json },
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -76,6 +76,18 @@ class Person
|
|||
owner.nil?
|
||||
end
|
||||
|
||||
def as_json(opts={})
|
||||
{
|
||||
:person => {
|
||||
:id => self.id,
|
||||
:name => self.real_name,
|
||||
:email => self.email,
|
||||
:url => self.url,
|
||||
:exported_key => exported_key
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
protected
|
||||
def clean_url
|
||||
self.url ||= "http://localhost:3000/" if self.class == User
|
||||
|
|
|
|||
|
|
@ -44,6 +44,15 @@ class Post
|
|||
signable_accessors.collect{|accessor|
|
||||
(self.send accessor.to_sym).to_s}.join ';'
|
||||
end
|
||||
|
||||
def as_json(opts={})
|
||||
{
|
||||
:post => {
|
||||
:id => self.id,
|
||||
:person => self.person.as_json,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
protected
|
||||
def destroy_comments
|
||||
|
|
|
|||
|
|
@ -281,6 +281,19 @@ class User
|
|||
def all_group_ids
|
||||
self.groups.all.collect{|x| x.id}
|
||||
end
|
||||
|
||||
def as_json(opts={})
|
||||
{
|
||||
:user => {
|
||||
:posts => self.raw_visible_posts.each{|post| post.as_json},
|
||||
:friends => self.friends.each {|friend| friend.as_json},
|
||||
:groups => self.groups.each {|group| group.as_json},
|
||||
:pending_requests => self.pending_requests.each{|request| request.as_json},
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def self.generate_key
|
||||
|
|
|
|||
Loading…
Reference in a new issue