質問編集履歴

1

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

2020/03/21 10:06

投稿

obr-note
obr-note

スコア16

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # エラー内容
6
6
 
7
- xxxxxxxx/views/trees/show.html.slim
7
+ xxx/app/views/trees/show.html.slim
8
8
 
9
9
  ```
10
10
 
@@ -72,6 +72,108 @@
72
72
 
73
73
 
74
74
 
75
+ # その他のコード
76
+
77
+ xxx/app/models/tree.rb
78
+
79
+ ```
80
+
81
+ class Tree < ApplicationRecord
82
+
83
+ validates :title, presence:true
84
+
85
+
86
+
87
+ belongs_to :user
88
+
89
+ has_many :responses
90
+
91
+ has_many :tree_categories, dependent: :destroy
92
+
93
+ has_many :categories, through: :tree_category, dependent: :destroy
94
+
95
+ end
96
+
97
+ ```
98
+
99
+
100
+
101
+ xxx/app/models/tree_category.rb
102
+
103
+ ```
104
+
105
+ class TreeCategory < ApplicationRecord
106
+
107
+ belongs_to :tree
108
+
109
+ belongs_to :category
110
+
111
+ end
112
+
113
+ ```
114
+
115
+ xxx/app/models/category.rb
116
+
117
+ ```
118
+
119
+ class Category < ApplicationRecord
120
+
121
+ has_many :tree_categories, dependent: :destroy
122
+
123
+ has_many :trees, through: :tree_categories, dependent: :destroy
124
+
125
+ end
126
+
127
+ ```
128
+
129
+
130
+
131
+ app/controllers/trees_controller.rb
132
+
133
+ ```
134
+
135
+ class TreesController < ApplicationController
136
+
137
+
138
+
139
+ ...
140
+
141
+
142
+
143
+ def show
144
+
145
+ @tree = Tree.find(params[:id])
146
+
147
+ @response = Response.new(:tree_id => params[:id])
148
+
149
+ @responses = @tree.responses.all
150
+
151
+ end
152
+
153
+
154
+
155
+ ...
156
+
157
+
158
+
159
+ private
160
+
161
+
162
+
163
+ def tree_params
164
+
165
+ params.require(:tree).permit(:title)
166
+
167
+ end
168
+
169
+ end
170
+
171
+ ```
172
+
173
+
174
+
175
+
176
+
75
177
  # 推測される原因
76
178
 
77
179
  collection_check_boxesの文法(collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block))の引数text_methodに:nameを指定したつもりですが、railsが理解していないのではないかと思います。