views:

28

answers:

1

I'm using the acts_as_auditable plugin, and the revisions attribute gives me this chunk of text (i.e. in the "revisions" column; i.e. @audit.revisions)

--- 
user_id: 2
kind: French
name: Delicious Pies

I'm trying to convert that text into a human-readable format to display the details of the audit. For instance, I want to convert the above chunk (i.e, @audit.revisions) into something like:

Created "Delicious Pies", which is a French cuisine.

I'm thinking something along the lines of:

Created "<%= @audit.revisions[:name] %>", which is a <%= @audit.revisions[:kind] %> cusine.

Of course, that seems to be incorrect. Any ideas on doing it correctly?

+4  A: 

If your revision column is a String then you can convert any YAML to hash with that:

y = YAML.load(@audit.revisions)
y["kind"] # => "French"

update: I said "hash" above but it will be converted to type that is appropriate for the given YAML. So it can be an array or object. But in your case it will be hash.

pawien
Perfect pawien! You're the best. Thank you so much! :)
sjsc