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

質問編集履歴

2

コントローラーの内容について追記しました。

2021/03/21 14:53

投稿

cherry2020
cherry2020

スコア10

title CHANGED
File without changes
body CHANGED
@@ -127,4 +127,34 @@
127
127
  ```
128
128
  console.log(`${item.worry}`)
129
129
  ```
130
- `item`モデルから`worry`カラムの内容を取得しているのですが、これがエラーになってしまいます。
130
+ `item`モデルから`worry`カラムの内容を取得しているのですが、これがエラーになってしまいます。
131
+
132
+ ## 追記 コントローラーについて
133
+
134
+ ```ruby
135
+
136
+ # app/controllers/troubles_controller.rbの内容
137
+
138
+ class TroublesController < ApplicationController
139
+ before_action :authenticate_user!
140
+
141
+ def index
142
+ @troubles = current_user.troubles.all.order(created_at: :desc)
143
+ @trouble = Trouble.new
144
+ end
145
+
146
+ def new
147
+ end
148
+
149
+ def create
150
+ trouble = Trouble.new(trouble_params)
151
+ render json: { trouble: trouble } if trouble.save
152
+ end
153
+
154
+ private
155
+
156
+ def trouble_params
157
+ params.require(:trouble).permit(:message_type, :worry).merge(user_id: current_user.id)
158
+ end
159
+ end
160
+ ```

1

検証ツールの内容について追記しました

2021/03/21 14:53

投稿

cherry2020
cherry2020

スコア10

title CHANGED
File without changes
body CHANGED
@@ -117,4 +117,14 @@
117
117
  - メソッドによるシンプルな呼び出しなのですが、どの部分がひっかかってしまっているのか分かりません。
118
118
  - 「こういった部分が原因では」など方向性やヒントでも構いませんので、アイデアをいただけると嬉しいです。
119
119
 
120
- どうぞよろしくお願いします。
120
+ どうぞよろしくお願いします。
121
+
122
+ ## 追記 検証ツールについて
123
+ ![イメージ説明](97120065ab04a5c5b437ebf2126d1a60.png)
124
+
125
+ `XMLHttpRequest`の中身が空なので、`sliceメソッド`は使えないというエラーが出ます。
126
+
127
+ ```
128
+ console.log(`${item.worry}`)
129
+ ```
130
+ `item`モデルから`worry`カラムの内容を取得しているのですが、これがエラーになってしまいます。