Ciao a tutti innanzitutto grazie per il vostro aiuto,
mi sto realizzando un applicativo nel mio controller ho questo codice:
posts = Post.all
render status: 200,
:json => { :success => true,
:info => 'User Profile Logged and is open',
:is_open => is_open,
:posts => posts
}
nel modello user ho:
def as_json(options = nil)
super(
:except => [
:email,
:role,
:city,
:cover,
:cover_content_type,
:cover_file_name,
:cover_file_size,
:cover_fingerprint,
:cover_new_content_type,
:cover_new_file_name,
:cover_new_file_size,
:cover_new_fingerprint,
:cover_new_updated_at,
:cover_updated_at,
:cover_x,
:cover_y,
:enabled,
:pic,
:pic_content_type,
:pic_file_name,
:pic_file_size,
:pic_fingerprint,
:pic_updated_at,
:updated_at,
:website
],
:include => [:fanpages],
:methods => [
:id,
:pic_url_thumb,
:pic_url,
:cover_feed_url,
:cover_url,
:cover_new_url,
:n_follows,
:n_followings,
:n_posts,
:fanpages_ref_ids,
:post_popular_ids,
:foollows_ids,
:last_follows,
:following_ids,
:last_followings,
:disciples_ids,
:discipling_ids,
]
)
end
nell model Post ho:
def as_json(options={})
attrs = super(options)
attrs["post_id"] = attrs["_id"].to_s
attrs["id"] = attrs["_id"].to_s
attrs["type"] = self.class.to_s.downcase
attrs["user"] = self.user.as_json(
only: [:name, :nickname],
:methods => [
:pic_url_thumb,
:pic_url
])
)
bene vorrei mostrare solo questi metodi (name, nickname) per
l’associazione con user ma invece mi da tt i metodi elencati nell modell
user.
grazie.