lib/jsonapi/routing_ext.rb in jsonapi-resources-0.10.0.beta3 vs lib/jsonapi/routing_ext.rb in jsonapi-resources-0.10.0.beta4

- old
+ new

@@ -18,10 +18,14 @@ def jsonapi_resource(*resources, &_block) @resource_type = resources.first res = JSONAPI::Resource.resource_klass_for(resource_type_with_module_prefix(@resource_type)) + unless res.singleton? + warn "Singleton routes created for non singleton resource #{res}. Links may not be generated correctly." + end + options = resources.extract_options!.dup options[:controller] ||= @resource_type options.merge!(res.routing_resource_options) options[:path] = format_route(@resource_type) @@ -78,10 +82,14 @@ def jsonapi_resources(*resources, &_block) @resource_type = resources.first res = JSONAPI::Resource.resource_klass_for(resource_type_with_module_prefix(@resource_type)) + if res.singleton? + warn "Singleton resource #{res} should use `jsonapi_resource` instead." + end + options = resources.extract_options!.dup options[:controller] ||= @resource_type options.merge!(res.routing_resource_options) options[:param] = :id @@ -152,11 +160,12 @@ methods = links_methods(options) if methods.include?(:show) match "relationships/#{formatted_relationship_name}", controller: options[:controller], - action: 'show_relationship', relationship: link_type.to_s, via: [:get] + action: 'show_relationship', relationship: link_type.to_s, via: [:get], + as: "relationships/#{link_type}" end if res.mutable? if methods.include?(:update) match "relationships/#{formatted_relationship_name}", controller: options[:controller], @@ -180,11 +189,12 @@ methods = links_methods(options) if methods.include?(:show) match "relationships/#{formatted_relationship_name}", controller: options[:controller], - action: 'show_relationship', relationship: link_type.to_s, via: [:get] + action: 'show_relationship', relationship: link_type.to_s, via: [:get], + as: "relationships/#{link_type}" end if res.mutable? if methods.include?(:create) match "relationships/#{formatted_relationship_name}", controller: options[:controller], @@ -219,11 +229,12 @@ options[:controller] ||= related_resource._type.to_s end match formatted_relationship_name, controller: options[:controller], relationship: relationship.name, source: resource_type_with_module_prefix(source._type), - action: 'show_related_resource', via: [:get] + action: 'show_related_resource', via: [:get], + as: relationship_name end def jsonapi_related_resources(*relationship) source = JSONAPI::Resource.resource_klass_for(resource_type_with_module_prefix) options = relationship.extract_options!.dup @@ -236,10 +247,11 @@ options[:controller] ||= related_resource._type.to_s match formatted_relationship_name, controller: options[:controller], relationship: relationship.name, source: resource_type_with_module_prefix(source._type), - action: 'index_related_resources', via: [:get] + action: 'index_related_resources', via: [:get], + as: relationship_name end protected # :nocov: def jsonapi_resource_scope(resource, resource_type) #:nodoc: