lib/jsonapi/routing_ext.rb in jsonapi-resources-0.0.4 vs lib/jsonapi/routing_ext.rb in jsonapi-resources-0.0.5

- old
+ new

@@ -45,11 +45,11 @@ end end end def links_methods(options) - default_methods = [:show, :create, :destroy] + default_methods = [:show, :create, :destroy, :update] if only = options[:only] Array(only).map(&:to_sym) elsif except = options[:except] default_methods - except else @@ -71,10 +71,14 @@ if methods.include?(:create) match "links/#{link_type}", controller: res._type.to_s, action: 'create_association', association: link_type.to_s, via: [:post] end + if methods.include?(:update) + match "links/#{link_type}", controller: res._type.to_s, action: 'update_association', association: link_type.to_s, via: [:put] + end + if methods.include?(:destroy) match "links/#{link_type}", controller: res._type.to_s, action: 'destroy_association', association: link_type.to_s, via: [:delete] end end @@ -90,9 +94,13 @@ match "links/#{link_type}", controller: res._type.to_s, action: 'show_association', association: link_type.to_s, via: [:get] end if methods.include?(:create) match "links/#{link_type}", controller: res._type.to_s, action: 'create_association', association: link_type.to_s, via: [:post] + end + + if methods.include?(:update) && res._association(link_type).acts_as_set + match "links/#{link_type}", controller: res._type.to_s, action: 'update_association', association: link_type.to_s, via: [:put] end if methods.include?(:destroy) match "links/#{link_type}/:keys", controller: res._type.to_s, action: 'destroy_association', association: link_type.to_s, via: [:delete] end \ No newline at end of file