testdouble/rails-training-201

Generate a JSON-formatted history containing all changes to Movies

Closed this issue · 0 comments

Challenge (1):

Look at the rails guides for active record callbacks: https://guides.rubyonrails.org/active_record_callbacks.html.

Implement a hook that writes the new version of any movie to /tmp/movies_<title>_<timestamp>.json

Here's a code snippet showing how you might write out a JSON file:

File.open("/tmp/temp.json","w") do |file|
  file.write({ foo: 'bar' }.to_json)
end

And here's how you might get a timestamp:

  def fresh_timestamp
    (DateTime.now.to_f * 1000).to_i
  end

Make sure to save the Director name along with the Movie's attributes.