Skip to content

Controller namespace lookup. #1436

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

Closed
wants to merge 7 commits into from

Conversation

beauby
Copy link
Contributor

@beauby beauby commented Jan 14, 2016

Just took a stab at it. Basically, it allows for inferring the serializer in the following scenario:

class Api::V1::PostController < ActionController::Base
  def create
    @post = Post.create(params)
    render json: @post
  end
end

class Api::V1::PostSerializer < ActiveModel::Serializer
  ...
end

Ref #1265, #886.

@beauby beauby changed the title Controller namespace lookup. [WIP] Controller namespace lookup. Jan 14, 2016
@beauby
Copy link
Contributor Author

beauby commented Jan 15, 2016

Note also that #1196 solves a different problem.

@bf4 bf4 mentioned this pull request Jan 15, 2016
@@ -56,7 +56,7 @@ def use_adapter?

[:_render_option_json, :_render_with_renderer_json].each do |renderer_method|
define_method renderer_method do |resource, options|
options.fetch(:serialization_context) { options[:serialization_context] = ActiveModelSerializers::SerializationContext.new(request) }
options[:serialization_context] = ActiveModelSerializers::SerializationContext.new(controller: self) unless options.key?(:serialization_context)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see this broken up in to multiple lines

unless options.key?(:serialization_context)
  options[:serialization_context] = ActiveModelSerializers::SerializationContext.new(controller: self)
end

@beauby beauby changed the title [WIP] Controller namespace lookup. Controller namespace lookup. Jan 20, 2016
serializer = ResourceNamespace::PostSerializer.serializer_for(comment)
assert_equal ResourceNamespace::PostSerializer::CommentSerializer, serializer
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test did not make sense anymore with the new lookup convention.

@jordanell
Copy link

Any progress here?

@NullVoxPopuli
Copy link
Contributor

@beauby, could you rebase?

we have another request for this feature, by @dgdosen

@beauby
Copy link
Contributor Author

beauby commented Mar 14, 2016

Closing this in favor of RFC #1442.

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

Successfully merging this pull request may close these issues.

4 participants