Hello... Given a database with records like the following Table: AuditLog Fields: ID | USERID | TYPE | TIME | DATA id:1, userId:1, type:PHOTO, time:2008-10-15 12:00:00, data: {photo_id:2089, photoname:"A trip to the beach"} Lets say the database had 50 records, with Rails How can I loop through the results as follows: <ul> <li> id, user_id, data.photoID, data.PhotoName</li> </ul> The main thing I don''t get is how to extract what''s inside the data column. Example given: @mystuff = AuditLog.all How to display something like mystuff.data.photo_id Thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Looks like I''m storing data correctly, I don''t want DATA to be a JSON object as it won''t be created via JavaScript but an Observer on certain models after_create etc... What do you think about using YAML? I was told Marshal was the way to go but after doing some google searches I found, there isn''t a lot of info on Marshal and it sounds like the community is against it... That being said, in sum: 1. What is the best way to store unsecured data in the data column 2. How to insert and extract from the database? Thank you On Sep 29, 8:11 pm, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello... > > Given a database with records like the following > Table: AuditLog > Fields: ID | USERID | TYPE | TIME | DATA > > id:1, userId:1, type:PHOTO, time:2008-10-15 12:00:00, data: > {photo_id:2089, photoname:"A trip to the beach"} > > Lets say the database had 50 records, with Rails How can I loop > through the results as follows: > > <ul> > <li> id, user_id, data.photoID, data.PhotoName</li> > </ul> > > The main thing I don''t get is how to extract what''s inside the data > column. Example given: > @mystuff = AuditLog.all > How to display something like mystuff.data.photo_id > > Thanks-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Sep-30 15:15 UTC
Re: Using Meta Data in a database field in a View
nobosh wrote:> Looks like I''m storing data correctly, I don''t want DATA to be a JSON > object as it won''t be created via JavaScript but an Observer on > certain models after_create etc... > > What do you think about using YAML? I was told Marshal was the way to > go but after doing some google searches I found, there isn''t a lot of > info on Marshal and it sounds like the community is against it... > > That being said, in sum: > > 1. What is the best way to store unsecured data in the data columnUse serialize.> 2. How to insert and extract from the database?Use serialize. Or better yet, don''t. Take the time to design a schema that actually has the fields you need. If you''re doing a lot of stuff with flexible attributes, a non-SQL database such as MongoDB or CouchDB may be a better fit.> > Thank youBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.