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

質問編集履歴

1

その他のコードを追加しました

2020/03/21 10:06

投稿

obr-note
obr-note

スコア16

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,7 @@
1
1
  プログラミング初心者です。Railsアプリを作成中です。
2
2
 
3
3
  # エラー内容
4
- xxxxxxxx/views/trees/show.html.slim
4
+ xxx/app/views/trees/show.html.slim
5
5
  ```
6
6
  h1 スレッドの新規登録
7
7
 
@@ -35,6 +35,57 @@
35
35
  https://qiita.com/cawaz3/items/e755a58177212f2aca6c
36
36
  カテゴリのチェックボックスを付けたいです。
37
37
 
38
+ # その他のコード
39
+ xxx/app/models/tree.rb
40
+ ```
41
+ class Tree < ApplicationRecord
42
+ validates :title, presence:true
43
+
44
+ belongs_to :user
45
+ has_many :responses
46
+ has_many :tree_categories, dependent: :destroy
47
+ has_many :categories, through: :tree_category, dependent: :destroy
48
+ end
49
+ ```
50
+
51
+ xxx/app/models/tree_category.rb
52
+ ```
53
+ class TreeCategory < ApplicationRecord
54
+ belongs_to :tree
55
+ belongs_to :category
56
+ end
57
+ ```
58
+ xxx/app/models/category.rb
59
+ ```
60
+ class Category < ApplicationRecord
61
+ has_many :tree_categories, dependent: :destroy
62
+ has_many :trees, through: :tree_categories, dependent: :destroy
63
+ end
64
+ ```
65
+
66
+ app/controllers/trees_controller.rb
67
+ ```
68
+ class TreesController < ApplicationController
69
+
70
+ ...
71
+
72
+ def show
73
+ @tree = Tree.find(params[:id])
74
+ @response = Response.new(:tree_id => params[:id])
75
+ @responses = @tree.responses.all
76
+ end
77
+
78
+ ...
79
+
80
+ private
81
+
82
+ def tree_params
83
+ params.require(:tree).permit(:title)
84
+ end
85
+ end
86
+ ```
87
+
88
+
38
89
  # 推測される原因
39
90
  collection_check_boxesの文法(collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block))の引数text_methodに:nameを指定したつもりですが、railsが理解していないのではないかと思います。
40
91
  解決方法調べましたが、分かりませんでした。