teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2018/03/18 13:14

投稿

katoy
katoy

スコア22328

answer CHANGED
@@ -1,3 +1,21 @@
1
1
  参考情報
2
2
  - Is there a way to get a collection of all the Models in your Rails app?
3
- [https://stackoverflow.com/questions/516579/](https://stackoverflow.com/questions/516579/)
3
+ [https://stackoverflow.com/questions/516579/](https://stackoverflow.com/questions/516579/)
4
+
5
+ 追記:
6
+ 上の web ページの情報の1つから、次のようにすることを思いつきます。
7
+
8
+ つぎのように aoo/models に モデル定義をしてある状況です。
9
+ ![イメージ説明](e2da7ff5df2f16532010117c14884318.png)
10
+
11
+ User モデルは定義していない事、Message モデルを定義している事を次の様に確認できます。
12
+ ```ruby
13
+ AR_MODEL_NAMES = ActiveRecord::Base.connection.tables.map do |model|
14
+ model.capitalize.singularize.camelize
15
+ end.freeze
16
+ AR_MODEL_NAMES.include?('User')
17
+ AR_MODEL_NAMES.include?('Message')
18
+ ```
19
+
20
+ rails console で試してみます。
21
+ ![イメージ説明](da61d861473b9799be7d13408da47c42.png)