Sorry for pulling out a two year old question (Best way to Serialize Models
<https://groups.google.com/forum/#!topic/sequel-talk/o2vVW2tURXw>), but
there is a piece of a puzzle still missing for me and I still don't know
how to do what I would like to:
# Using roda's :json plugin
plugin :json, classes => [Array, Hash, Sequel::Model]
# In the main route start collecting different things in a hash @rs that we
be sent to the client as JSON at the end
route do |r|
@rs = {}
# user record, this is DB persisted session
@rs[:user] = current_user(r.cookies('SESSIONID'))
# Maybe some other record that will be sent on every request
@rs[:user_settings] = user_settings(@rs[:user][:id])
r.multi_route
end
# in the multi_route branch
r.get "jobs" do
@rs[:jobs] = Job.where(:id => [100,101]).eager(:job_items).all
# and the last statement of every route would be @rs which will be
converted to JSON by roda's :json plugin
# this pattern works great when @rs hash values are arrays and hashes,
but Models in the mix don't work)
@rs
end
Thanks.
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/d03327da-aba8-467f-b051-f5ef2e89dd13%40googlegroups.com.