Skip to content

Commit 90d90fa

Browse files
committed
Exclude edit and new routes
1 parent 03458d6 commit 90d90fa

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,6 @@ contact_links_phone_numbers GET /contacts/:contact_id/links/phone-numbers(
890890
contact_phone_numbers GET /contacts/:contact_id/phone-numbers(.:format) phone_numbers#get_related_resources {:association=>"phone_numbers", :source=>"contacts"}
891891
contacts GET /contacts(.:format) contacts#index
892892
POST /contacts(.:format) contacts#create
893-
new_contact GET /contacts/new(.:format) contacts#new
894-
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
895893
contact GET /contacts/:id(.:format) contacts#show
896894
PATCH /contacts/:id(.:format) contacts#update
897895
PUT /contacts/:id(.:format) contacts#update
@@ -902,8 +900,6 @@ contact_links_phone_numbers GET /contacts/:contact_id/links/phone-numbers(
902900
phone_number_contact GET /phone-numbers/:phone_number_id/contact(.:format) contacts#get_related_resource {:association=>"contact", :source=>"phone_numbers"}
903901
phone_numbers GET /phone-numbers(.:format) phone_numbers#index
904902
POST /phone-numbers(.:format) phone_numbers#create
905-
new_phone_number GET /phone-numbers/new(.:format) phone_numbers#new
906-
edit_phone_number GET /phone-numbers/:id/edit(.:format) phone_numbers#edit
907903
phone_number GET /phone-numbers/:id(.:format) phone_numbers#show
908904
PATCH /phone-numbers/:id(.:format) phone_numbers#update
909905
PUT /phone-numbers/:id(.:format) phone_numbers#update
@@ -933,8 +929,6 @@ gives routes that are only related to the primary resource, and none for its rel
933929
Prefix Verb URI Pattern Controller#Action
934930
contacts GET /contacts(.:format) contacts#index
935931
POST /contacts(.:format) contacts#create
936-
new_contact GET /contacts/new(.:format) contacts#new
937-
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
938932
contact GET /contacts/:id(.:format) contacts#show
939933
PATCH /contacts/:id(.:format) contacts#update
940934
PUT /contacts/:id(.:format) contacts#update
@@ -973,8 +967,6 @@ contact_links_phone_numbers GET /contacts/:contact_id/links/phone-numbers(.:f
973967
DELETE /contacts/:contact_id/links/phone-numbers/:keys(.:format) contacts#destroy_association {:association=>"phone_numbers"}
974968
contacts GET /contacts(.:format) contacts#index
975969
POST /contacts(.:format) contacts#create
976-
new_contact GET /contacts/new(.:format) contacts#new
977-
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
978970
contact GET /contacts/:id(.:format) contacts#show
979971
PATCH /contacts/:id(.:format) contacts#update
980972
PUT /contacts/:id(.:format) contacts#update
@@ -1004,8 +996,6 @@ gives the following routes:
1004996
contact_phone_numbers GET /contacts/:contact_id/phone-numbers(.:format) phone_numbers#get_related_resources {:association=>"phone_numbers", :source=>"contacts"}
1005997
contacts GET /contacts(.:format) contacts#index
1006998
POST /contacts(.:format) contacts#create
1007-
new_contact GET /contacts/new(.:format) contacts#new
1008-
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
1009999
contact GET /contacts/:id(.:format) contacts#show
10101000
PATCH /contacts/:id(.:format) contacts#update
10111001
PUT /contacts/:id(.:format) contacts#update
@@ -1034,8 +1024,6 @@ gives the following routes:
10341024
phone_number_contact GET /phone-numbers/:phone_number_id/contact(.:format) contacts#get_related_resource {:association=>"contact", :source=>"phone_numbers"}
10351025
phone_numbers GET /phone-numbers(.:format) phone_numbers#index
10361026
POST /phone-numbers(.:format) phone_numbers#create
1037-
new_phone_number GET /phone-numbers/new(.:format) phone_numbers#new
1038-
edit_phone_number GET /phone-numbers/:id/edit(.:format) phone_numbers#edit
10391027
phone_number GET /phone-numbers/:id(.:format) phone_numbers#show
10401028
PATCH /phone-numbers/:id(.:format) phone_numbers#update
10411029
PUT /phone-numbers/:id(.:format) phone_numbers#update

lib/jsonapi/routing_ext.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def jsonapi_resource(*resources, &block)
2626
options.merge!(res.routing_resource_options)
2727
options[:path] = format_route(@resource_type)
2828

29+
if options[:except]
30+
options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new')
31+
options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit')
32+
else
33+
options[:except] = [:new, :edit]
34+
end
35+
2936
resource @resource_type, options do
3037
@scope[:jsonapi_resource] = @resource_type
3138

@@ -62,6 +69,13 @@ def jsonapi_resources(*resources, &block)
6269

6370
options[:path] = format_route(@resource_type)
6471

72+
if options[:except]
73+
options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new')
74+
options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit')
75+
else
76+
options[:except] = [:new, :edit]
77+
end
78+
6579
resources @resource_type, options do
6680
@scope[:jsonapi_resource] = @resource_type
6781

test/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def count_queries(&block)
113113
jsonapi_link :author, except: [:destroy]
114114
end
115115

116-
jsonapi_resource :preferences
116+
jsonapi_resource :preferences, except: [:create, :destroy]
117117

118118
jsonapi_resources :books
119119
jsonapi_resources :book_comments

0 commit comments

Comments
 (0)