I'm building a web API with Ruby, Grape and ActiveRecord. Coming from ASP.NET Web API I'm used to having automatic model binding from JSON to a class object which then can be saved with Entity Framework. I have been searching a bit to find out if there is anything similiar to this when using ActiveRecord but haven't found anything which make me think that I'm missing something really obvious. What is the best way to deserialize JSON into ActiveRecord models?
UPDATE
Matts answer worked great for simple types but when I'm having associations I get the following error: ActiveRecord::AssociationTypeMismatch: Connector(#70297711668780) expected, got Hash(#70297701477140)
This is the code I'm running
class Card < ActiveRecord::Base
has_many :connectors, autosave: true
end
class Connector < ActiveRecord::Base
has_one :card
has_one :connected_card, :class_name => "Card", :foreign_key => "connected_card_id"
end
json = "{\"id\":\"1\", \"connectors\": [{\"id\": 1, \"card_id\":1}]}"
card = Card.new(ActiveSupport::JSON.decode(json))