質問編集履歴
6
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -140,7 +140,7 @@
|
|
140
140
|
### 試したこと2
|
141
141
|
app/models/bicycle_log.rb
|
142
142
|
|
143
|
-
```
|
143
|
+
```ruby
|
144
144
|
def a
|
145
145
|
bicycle_log_ids = BicycleLog.where.not(return_datetime: nil).group(:bicycle_id).maximum(:return_datetime).values
|
146
146
|
Bicycle.left_joins(:bicycle_logs).merge(BicycleLog.where(id: bicycle_log_ids)).select("bicycles.*, bicycle_logs.*")
|
@@ -149,7 +149,7 @@
|
|
149
149
|
|
150
150
|
app/views/bicycles/index.html.slim
|
151
151
|
|
152
|
-
```
|
152
|
+
```ruby
|
153
153
|
= render_with_pagination(paintcans) do |paintcans|
|
154
154
|
.table-sticky.max-vh-70
|
155
155
|
table.table.table-sm.table-bordered.table-striped.table-hover.text-nowrap
|
5
yuma.inauraさんの回答を参考にしての追加事項
test
CHANGED
File without changes
|
test
CHANGED
@@ -137,6 +137,34 @@
|
|
137
137
|
省略
|
138
138
|
```
|
139
139
|
|
140
|
+
### 試したこと2
|
141
|
+
app/models/bicycle_log.rb
|
142
|
+
|
143
|
+
```
|
144
|
+
def a
|
145
|
+
bicycle_log_ids = BicycleLog.where.not(return_datetime: nil).group(:bicycle_id).maximum(:return_datetime).values
|
146
|
+
Bicycle.left_joins(:bicycle_logs).merge(BicycleLog.where(id: bicycle_log_ids)).select("bicycles.*, bicycle_logs.*")
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
app/views/bicycles/index.html.slim
|
151
|
+
|
152
|
+
```
|
153
|
+
= render_with_pagination(paintcans) do |paintcans|
|
154
|
+
.table-sticky.max-vh-70
|
155
|
+
table.table.table-sm.table-bordered.table-striped.table-hover.text-nowrap
|
156
|
+
thead
|
157
|
+
tr
|
158
|
+
tbody
|
159
|
+
- bicycles.each do |bicycle|
|
160
|
+
tr
|
161
|
+
省略
|
162
|
+
- paintcan.paintcan_logs.each do |paintcan_log|
|
163
|
+
td= paintcan_log.a
|
164
|
+
省略
|
165
|
+
```
|
166
|
+

|
167
|
+
|
140
168
|
### 補足情報(FW/ツールのバージョンなど)
|
141
169
|
バージョン情報
|
142
170
|
Rails 6.1.4.7
|
4
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -63,16 +63,7 @@
|
|
63
63
|
td= bicycle_log.return_datetime
|
64
64
|
省略
|
65
65
|
```
|
66
|
-
include Order
|
67
|
-
|
68
|
-
app/models/
|
66
|
+
app/models/bicycle.rb
|
69
|
-
|
70
|
-
scope :search, ->(params){
|
71
|
-
result = self
|
72
|
-
|
73
|
-
result
|
74
|
-
}
|
75
|
-
|
76
67
|
```ruby
|
77
68
|
include Order
|
78
69
|
|
@@ -85,9 +76,11 @@
|
|
85
76
|
}
|
86
77
|
```
|
87
78
|
|
88
|
-
app/models/
|
79
|
+
app/models/bicycle_log.rb
|
89
80
|
|
90
81
|
```ruby
|
82
|
+
include Order
|
83
|
+
|
91
84
|
belongs_to :bicycle, optional: false
|
92
85
|
|
93
86
|
scope :search, ->(params){
|
3
モデル、コントローラーの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -63,16 +63,47 @@
|
|
63
63
|
td= bicycle_log.return_datetime
|
64
64
|
省略
|
65
65
|
```
|
66
|
+
include Order
|
67
|
+
|
66
68
|
app/models/paintcan.rb
|
67
69
|
|
70
|
+
scope :search, ->(params){
|
71
|
+
result = self
|
72
|
+
|
73
|
+
result
|
74
|
+
}
|
75
|
+
|
68
76
|
```ruby
|
77
|
+
include Order
|
78
|
+
|
69
79
|
has_many :bicycle_logs, dependent: :restrict_with_error
|
80
|
+
|
81
|
+
scope :search, ->(params){
|
82
|
+
result = self
|
83
|
+
|
84
|
+
result
|
85
|
+
}
|
70
86
|
```
|
71
87
|
|
72
88
|
app/models/paintcan_log.rb
|
73
89
|
|
74
90
|
```ruby
|
75
91
|
belongs_to :bicycle, optional: false
|
92
|
+
|
93
|
+
scope :search, ->(params){
|
94
|
+
result = self
|
95
|
+
|
96
|
+
result
|
97
|
+
}
|
98
|
+
```
|
99
|
+
app/controllers/bicycles_controller.rb
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
def index
|
103
|
+
@bicycles = Bicycle
|
104
|
+
.search(params)
|
105
|
+
.order_by(params[:sort])
|
106
|
+
end
|
76
107
|
```
|
77
108
|
|
78
109
|
### 試したこと
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -77,10 +77,10 @@
|
|
77
77
|
|
78
78
|
### 試したこと
|
79
79
|
モデルにメソッドを定義し、VIEWに表示させました。以下のコメントアウトした様々な方法で返却日時であるreturn_datetimeを表示させた上で最新のデータのみを表示させようとしましたが、上手く行かず、何か思いつく方法があれば、教えて頂けると幸いです。
|
80
|
-
app/models/
|
80
|
+
app/models/bicycle_log.rb
|
81
81
|
```ruby
|
82
82
|
def a
|
83
|
-
|
83
|
+
bicycle_logs = BicycleLog
|
84
84
|
# .search(params)
|
85
85
|
# .order_by(params[:sort])
|
86
86
|
# .find(&:return_datetime).last
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -35,7 +35,6 @@
|
|
35
35
|
|
36
36
|
### 実現したいこと
|
37
37
|
|
38
|
-
ここに実現したいことを箇条書きで書いてください。
|
39
38
|
自転車一覧画面に自転車の使用履歴にある最新の返却日時のみを表示させたい。
|
40
39
|
|
41
40
|
### 発生している問題・エラーメッセージ
|