开发者

Rails recent activity model

I have a rails model called "ActivityStream" in this model I have these members account_id :integer project_id :integer开发者_如何学Go activity_type :string data :binary

in the data field I want to store an object (model) so that I can show the activity to the user.

I have an observer on the project class, where I do this: http://pastie.org/1440976

The problem is that what is being saved to the database is only the ID of the record or I get an exception on the gsub method (I am using sqlite3 in development)

My question is: What can I do to store the model inside the data column so that I can then retrieve it with ease.

B.T.W I am using rails 3


Sometime ago I created a gem exactly for this. Source code might come in handy in your case: https://rubygems.org/gems/public_activity


ActiveRecord handles this situation by providing the ActiveRecord::Base.serialize class method: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-serialize

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜