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

質問編集履歴

2

文法の修正

2021/02/18 01:24

投稿

taka3344
taka3344

スコア8

title CHANGED
File without changes
body CHANGED
@@ -15,8 +15,13 @@
15
15
  Routes match in priority from top to bottom
16
16
 
17
17
 
18
- というエラーがコンソールに初めから出てしまっています。また、いいねボタンをクリックすると追加で
18
+ というエラーがコンソールに初めから出てしまっています。
19
+ ↑解決しました
20
+ ------------------------------------------------------------------------------------
19
21
 
22
+
23
+ また、いいねボタンをクリックすると追加で
24
+
20
25
  VM826 application-34…e09f93ac287.js:1616 ITEM http://localhost:3000/items/1/favorites 500 (Internal Server Error)
21
26
  ./node_modules/@rails/ujs/lib/assets/compiled/rails-ujs.js.Rails.ajax @ VM826 application-34…e09f93ac287.js:1616
22
27
  ./node_modules/@rails/ujs/lib/assets/compiled/rails-ujs.js.Rails.handleRemote @ VM826 application-34…e09f93ac287.js:2052
@@ -111,6 +116,33 @@
111
116
  ソースコード
112
117
  $("#favorite_<%= @item.id %>").html("<%= j(render partial: 'favorites/favorite', locals: { item: @item }) %>");
113
118
  ```
119
+ ##### favoriteモデル
120
+ ```ここに言語名を入力
121
+ class Favorite < ApplicationRecord
122
+ belongs_to :user
123
+ belongs_to :item
124
+
125
+
126
+ validates_uniqueness_of :item_id, scope: :user_id
127
+ end
128
+ ```
129
+ ##### item モデル
130
+ ```ここに言語名を入力
131
+ class Item < ApplicationRecord
132
+ extend ActiveHash::Associations::ActiveRecordExtensions
133
+ belongs_to :category
134
+ belongs_to :state
135
+ belongs_to :shopping_fee
136
+ belongs_to :shopping_day
137
+ belongs_to :area
138
+
139
+ belongs_to :seller
140
+ has_one :order
141
+ has_one_attached :image
142
+ has_many :favorites, dependent: :destroy
143
+ ```
144
+
145
+
114
146
  ### 試したこと
115
147
 
116
148
  ルーティングができていないのかと思い、rails routesで確認しました。

1

誤字による変更

2021/02/18 01:24

投稿

taka3344
taka3344

スコア8

title CHANGED
File without changes
body CHANGED
@@ -117,6 +117,7 @@
117
117
  item_favorites POST /items/:item_id/favorites(.:format) favorites#create
118
118
  item_favorite DELETE /items/:item_id/favorites/:id(.:format) favorites#destroy
119
119
  と、しっかりルーティングはできていました。
120
+ この先どのようにエラー解決していくかわかりません...
120
121
  初心者ですので、教えていただければ幸いです。よろしくお願いいたします。
121
122
  ### 補足情報(FW/ツールのバージョンなど)
122
123