Merge pull request #1289 from tchak/serialization_context

rename context to serialization_context and add url helpers
This commit is contained in:
L. Preston Sego III
2015-10-29 07:56:47 -04:00
7 changed files with 35 additions and 7 deletions

View File

@@ -206,7 +206,7 @@ module ActiveModel
end
def links_for(serializer, options)
JsonApi::PaginationLinks.new(serializer.object, options[:context]).serializable_hash(options)
JsonApi::PaginationLinks.new(serializer.object, options[:serialization_context]).serializable_hash(options)
end
end
end

View File

@@ -41,11 +41,11 @@ module ActiveModel
end
def url(options)
@url ||= options.fetch(:links, {}).fetch(:self, nil) || original_url
@url ||= options.fetch(:links, {}).fetch(:self, nil) || request_url
end
def original_url
@original_url ||= context.original_url[/\A[^?]+/]
def request_url
@request_url ||= context.request_url
end
def query_parameters

View File

@@ -7,6 +7,18 @@ module ActiveModel
end
end
initializer 'active_model_serializers.url_helpers' do
ActiveSupport.on_load(:action_controller) do
ActiveModelSerializers.url_helpers = Module.new do
include Rails.application.routes.url_helpers
def self.default_url_options
ActionController::Base.default_url_options
end
end
end
end
initializer 'generators' do |app|
app.load_generators
require 'generators/serializer/resource_override'