Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PORO description #407

Closed
wants to merge 1 commit into from
Closed

Update PORO description #407

wants to merge 1 commit into from

Conversation

harlow
Copy link

@harlow harlow commented Oct 19, 2013

It's not entirely clear how read_attribute_for_serialization is supposed to be implemented. I had to look back at the older README to find the mention of ActiveModel::SerializerSupport.

class Poro
   include ActiveModel::SerializerSupport

   # ...
end

Is there a better way to handle this?

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling d92bd15 on harlow:hw-updated-readme into c65d387 on rails-api:master.

@spastorino
Copy link
Contributor

There's no ActiveModel::SerializerSupport anymore. The typical way to implement read_attribute_for_serialization is as an alias to send, but the method is still there in case developers want to decorate what send returns.

@harlow
Copy link
Author

harlow commented Oct 19, 2013

@spastorino thanks for the quick reply. Do you mind expanding on that a little more? For example we've been using PORO's for object-graphs that don't have immediate relations between models i.e.:

class Poro
   inculde AciveModel::Model

   def some_array_of_foo_objects
   end

   def some_other_non_related_bar_object
   end

   def read_attribute_for_serialization
     # what goes here?
   end
end

Then a serializer

class PoroSerializer
   has_many :some_array_of_foo_objects
   has_one :some_other_non_related_bar_object
end

Maybe I'm looking at it the wrong way. Let me know if you have some more details on this and I'll get the README updated appropriately.

@spastorino
Copy link
Contributor

You can do ... alias read_attribute_for_serialization send
For more info https://github.com/rails/rails/blob/cc8d1482/activemodel/lib/active_model/serialization.rb#L125-141

@harlow
Copy link
Author

harlow commented Oct 20, 2013

Thanks for the note. Closing this as it's not longer relevant.

@harlow harlow closed this Oct 20, 2013
@mech
Copy link

mech commented Jan 9, 2014

Hi, I include ActiveModel::SerializerSupport because I need the controller to automatically find out where to look for the serializer because of active_model_serializer. If there is no more ActiveModel::SerializerSupport support, may I know how my PORO can let my controller know where to find it automatically rather than using the serializer

respond_with @company, serializer: MySerializerWhichAMSCantFind

@spastorino
Copy link
Contributor

ActiveModel::SerializerSupport is there :)

@stevenharman
Copy link

I believe @mech was referring to the old (pre 0.9.0) behavior of ActiveModel::SerializerSupport adding a #serliazer_for method to any object into which it was included. We no longer rely on that an instead rely on a convention of class named Poro using a PoroSerializer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants