質問編集履歴
2
問題が起こるルーティング設定でのルーティングヘルパーの情報を具体的に提示。
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,4 +37,26 @@
|
|
37
37
|
|
38
38
|
このとき、`hoge2/fuga` に関するパスでルーティングヘルパーが作られない現象を確認できました。
|
39
39
|
|
40
|
-
現象が起こるのは`resources :hoge1`と`resources: hoge2`のそれぞれの中にある`resources :fuga`の`:fuga`の名称がそれぞれで一致している場合に現象を再現できました。
|
40
|
+
現象が起こるのは`resources :hoge1`と`resources: hoge2`のそれぞれの中にある`resources :fuga`の`:fuga`の名称がそれぞれで一致している場合に現象を再現できました。
|
41
|
+
|
42
|
+
---
|
43
|
+
|
44
|
+
追記
|
45
|
+
上記の`config/routes.rb`の設定の時、Railsサーバーの`rails/info/routes`にアクセスして得られるルーティングの情報は以下のようになります。
|
46
|
+
|
47
|
+
|Helper|HTTP Verb|Path|Controller#Action|
|
48
|
+
|---|---|---|---|
|
49
|
+
|fuga_index_path|GET|/hoge1/fuga(.:format)|bar/fuga#index|
|
50
|
+
||POST|/hoge1/fuga(.:format)|bar/fuga#create|
|
51
|
+
|fuga_path|GET|/hoge1/fuga/:id(.:format)|bar/fuga#show|
|
52
|
+
||PATCH|/hoge1/fuga/:id(.:format)|bar/fuga#update|
|
53
|
+
||PUT|/hoge1/fuga/:id(.:format)|bar/fuga#update|
|
54
|
+
||DELETE|/hoge1/fuga/:id(.:format)|bar/fuga#destroy|
|
55
|
+
||GET|/hoge2/fuga(.:format)|fuga#index|
|
56
|
+
||POST|/hoge2/fuga(.:format)|fuga#create|
|
57
|
+
||GET|/hoge2/fuga/:id(.:format)|fuga#show|
|
58
|
+
||PATCH|/hoge2/fuga/:id(.:format)|fuga#update|
|
59
|
+
||PUT|/hoge2/fuga/:id(.:format)|fuga#update|
|
60
|
+
||DELETE|/hoge2/fuga/:id(.:format)|fuga#destroy|
|
61
|
+
|
62
|
+
ご覧のように `/hoge1/fuga(.:format)`と`/hoge1/fuga/:id(.:format)`についてはルーティングヘルパーが示されていますが、`/hoge2/fuga(.:format)`と`/hoge2/fuga/:id(.:format)`のルーティングヘルパーは示されません。
|
1
問題が起こる設定の実例を提示。
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,4 +11,30 @@
|
|
11
11
|
|
12
12
|
これは「同一のパスでHTTPメソッドが異なるルーティング」ではなく「**同じパス全てでルーティングヘルパーがない**」というような状況です。
|
13
13
|
|
14
|
-
このように、Railsにおいてルーティングヘルパーが作られない条件が何かしらあるように思うのですが、その条件の仕様について説明された公式に近いドキュメントはありますでしょうか?
|
14
|
+
このように、Railsにおいてルーティングヘルパーが作られない条件が何かしらあるように思うのですが、その条件の仕様について説明された公式に近いドキュメントはありますでしょうか?
|
15
|
+
|
16
|
+
---
|
17
|
+
追記
|
18
|
+
問題を確認したルーティング設定はプロダクトコードでそのまま設定を載せることが出来ないため、問題の症状が確認され続ける限り設定を削減して、最終的に残った設定のうち名称を変更したものを以下に載せます。
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
# config/routes.rb
|
22
|
+
Rails.application.routes.draw do
|
23
|
+
resources :hoge1, only: [] do
|
24
|
+
collection do
|
25
|
+
scope module: :bar do
|
26
|
+
resources :fuga
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
resources :hoge2, only: [] do
|
31
|
+
collection do
|
32
|
+
resources :fuga
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
このとき、`hoge2/fuga` に関するパスでルーティングヘルパーが作られない現象を確認できました。
|
39
|
+
|
40
|
+
現象が起こるのは`resources :hoge1`と`resources: hoge2`のそれぞれの中にある`resources :fuga`の`:fuga`の名称がそれぞれで一致している場合に現象を再現できました。
|