lib/roar/rails/controller_additions.rb in roar-rails-0.0.12 vs lib/roar/rails/controller_additions.rb in roar-rails-0.0.13

- old
+ new

@@ -1,11 +1,11 @@ require 'hooks/inheritable_attribute' +require 'roar/rails/responder' module Roar::Rails module ControllerAdditions extend ActiveSupport::Concern - include ModelMethods included do extend Hooks::InheritableAttribute inheritable_attr :represents_options self.represents_options ||= {} @@ -35,21 +35,20 @@ end end def consume!(model, options={}) - format = formats.first # FIXME: i expected request.content_mime_type to do the job. copied from responder.rb. this will return the wrong format when the controller responds to :json and :xml and the Content-type is :xml (?) - model = prepare_model_for(format, model, options) + format = formats.first # FIXME: i expected request.content_mime_type to do the job. copied from responder.rb. this will return the wrong format when the controller responds to :json and :xml and the Content-type is :xml (?) + representer = prepare_model_for(format, model, options) - model.send(compute_parsing_method(format), incoming_string) # e.g. from_json("...") + representer.send(compute_parsing_method(format), incoming_string, options) # e.g. from_json("...") model end def prepare_model_for(format, model, options) representer = representer_for(format, model, options) - extend_with!(model, representer) - model + representer.prepare(model) end # Central entry-point for finding the appropriate representer. def representer_for(format, model, options={}) options.delete(:represent_with) || representer_name_for(format, model) @@ -73,6 +72,6 @@ return self.class.represents_options[format][:collection] if model.kind_of?(Array) self.class.represents_options[format][:entity] end end -end +end \ No newline at end of file