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

Documentation for serializing resources without render #1139

Merged
merged 1 commit into from
Sep 12, 2015
Merged

Documentation for serializing resources without render #1139

merged 1 commit into from
Sep 12, 2015

Conversation

PericlesTheo
Copy link
Contributor

@NullVoxPopuli
Copy link
Contributor

I like this. good work!

the resource you want to be serialized and call `.serializable_hash`.

```ruby
def create
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the sake of readme length, do you think this should be simplified?

having context is nice though.

@joaomdmoura, what are your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea initially I had it a bit shorter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NullVoxPopuli do you mean the code example or the text? Or both? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just the code example. the text is great! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about?

def create
  @message = current_user.messages.create!(message_params)
   MessageCreationWorker.perform(serialized_message)
   head 204
end

def serialized_message
  ActiveModel::SerializableResource.new(@message).serializable_hash
end

Less verbose and still has some contextual meaning

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥

@NullVoxPopuli
Copy link
Contributor

looks good!

NullVoxPopuli added a commit that referenced this pull request Sep 12, 2015
Documentation for serializing resources without render
@NullVoxPopuli NullVoxPopuli merged commit b9b94f0 into rails-api:master Sep 12, 2015
@PericlesTheo
Copy link
Contributor Author

@NullVoxPopuli cheers that was superfast! ❤️

```ruby
def create
@message = current_user.messages.create!(message_params)
MessageCreationWorker.perform(serialized_message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

@joaomdmoura
Copy link
Member

👍

@PericlesTheo PericlesTheo deleted the serializer_without_render_doc branch December 4, 2016 10:09
@Awatatah
Copy link

I am trying this and I am getting NameError: uninitialized constant ActiveModel::SerializableResource

@bf4
Copy link
Member

bf4 commented Jan 31, 2017

@Awatatah That's because you presumably have a typo ActiveModel::SerializableResource should be ActiveModelSerializers::SerializableResource. Please don't comment on closed years old issue. Please open a new issue if you continue to have trouble resolving this.

@rails-api rails-api locked and limited conversation to collaborators Jan 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants