Skip to content

Instantly share code, notes, and snippets.

@wooly
Created April 24, 2012 13:05
Show Gist options
  • Save wooly/2479480 to your computer and use it in GitHub Desktop.
Save wooly/2479480 to your computer and use it in GitHub Desktop.
class Response < ActiveRecord::Base
serialize :answers
end
# rails c
irb(main):022:0> [{"answers" => {"foo" => "bar"}}].map {|response| Response.new(response)}
=> [#<Response id: nil, answers: {"foo"=>"bar"}, created_at: nil, updated_at: nil, questionnaire_id: nil>]
Hooray!
# responses_controller.rb
workingResponses = [{"answers" => {"foo" => "bar"}}].map {|resp| Response.new{resp}}
logger.debug(workingResponses)
# logger output:
[#<Response id: nil, answers: nil, created_at: nil, updated_at: nil, questionnaire_id: nil>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment