mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add URL to serializers (closes #61)
Thanks so much to @vanstee for the initial implementation!
This commit is contained in:
@@ -49,6 +49,7 @@ module ActionController
|
||||
|
||||
if serializer
|
||||
options[:scope] = serialization_scope
|
||||
options[:url_options] = url_options
|
||||
json = serializer.new(json, options.merge(default_serializer_options || {}))
|
||||
end
|
||||
super
|
||||
|
||||
@@ -380,6 +380,10 @@ module ActiveModel
|
||||
@object, @options = object, options
|
||||
end
|
||||
|
||||
def url_options
|
||||
@options[:url_options]
|
||||
end
|
||||
|
||||
# Returns a json representation of the serializable
|
||||
# object including the root.
|
||||
def as_json(options=nil)
|
||||
|
||||
@@ -10,6 +10,12 @@ if defined?(Rails)
|
||||
Rails::Generators.configure!(app.config.generators)
|
||||
require "generators/resource_override"
|
||||
end
|
||||
|
||||
initializer "include_routes.active_model_serializer" do |app|
|
||||
ActiveSupport.on_load(:active_model_serializers) do
|
||||
include app.routes.url_helpers
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user