質問編集履歴

1

一部ソースコードの削除

2020/08/23 17:30

投稿

KURUMAEBI
KURUMAEBI

スコア2

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
- 初質問なので足りないソースコードなどあったら随時指摘してください。
3
+ 質問なので足りないソースコードなどあったら随時指摘してください。
4
4
 
5
5
  railsで音楽アプリの投稿機能を作っています。
6
6
 
@@ -44,210 +44,200 @@
44
44
 
45
45
  ________________________________________________________________________________
46
46
 
47
+
48
+
47
- _track.html.erb /一応載せておきます。
49
+ schema.rb
48
-
49
-
50
-
50
+
51
+
52
+
51
- <%= image_tag track.track_image_id.url if track.track_image_id? %>
53
+ create_table "tracks", force: :cascade do |t|
52
-
53
-
54
-
54
+
55
- <%= audio_tag track.track_audio_id.url if track.track_audio_id? %>
55
+ t.string "track_audio_id"
56
+
57
+ t.string "track_image_id"
58
+
59
+ t.string "title"
60
+
61
+ t.text "description"
62
+
63
+ t.integer "user_id"
64
+
65
+ t.datetime "created_at", null: false
66
+
67
+ t.datetime "updated_at", null: false
68
+
69
+ end
56
70
 
57
71
  ________________________________________________________________________________
58
72
 
59
- schema.rb
60
-
61
-
62
-
63
- create_table "tracks", force: :cascade do |t|
64
-
65
- t.string "track_audio_id"
66
-
67
- t.string "track_image_id"
68
-
69
- t.string "title"
70
-
71
- t.text "description"
72
-
73
- t.integer "user_id"
74
-
75
- t.datetime "created_at", null: false
76
-
77
- t.datetime "updated_at", null: false
78
-
79
- end
73
+ audio_file_uploader.rb
74
+
75
+
76
+
77
+ class AudioFileUploader < CarrierWave::Uploader::Base
78
+
79
+ # Include RMagick or MiniMagick support:
80
+
81
+ # include CarrierWave::RMagick
82
+
83
+ # include CarrierWave::MiniMagick
84
+
85
+ include CarrierWave::Audio
86
+
87
+
88
+
89
+ # Choose what kind of storage to use for this uploader:
90
+
91
+ storage :file
92
+
93
+ # storage :fog
94
+
95
+
96
+
97
+ # Override the directory where uploaded files will be stored.
98
+
99
+ # This is a sensible default for uploaders that are meant to be mounted:
100
+
101
+ def store_dir
102
+
103
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
104
+
105
+ end
106
+
107
+
108
+
109
+ # Provide a default URL as a default if there hasn't been a file uploaded:
110
+
111
+ # def default_url(*args)
112
+
113
+ # # For Rails 3.1+ asset pipeline compatibility:
114
+
115
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
116
+
117
+ #
118
+
119
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
120
+
121
+ # end
122
+
123
+
124
+
125
+ # Process files as they are uploaded:
126
+
127
+ # process scale: [200, 300]
128
+
129
+ #
130
+
131
+ # def scale(width, height)
132
+
133
+ # # do something
134
+
135
+ # end
136
+
137
+
138
+
139
+ # Create different versions of your uploaded files:
140
+
141
+ # version :thumb do
142
+
143
+ # process resize_to_fit: [50, 50]
144
+
145
+ # end
146
+
147
+
148
+
149
+ # Add a white list of extensions which are allowed to be uploaded.
150
+
151
+ # For images you might use something like this:
152
+
153
+ # def extension_whitelist
154
+
155
+ # %w(jpg jpeg gif png)
156
+
157
+ # end
158
+
159
+
160
+
161
+ # Override the filename of the uploaded files:
162
+
163
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
164
+
165
+ # def filename
166
+
167
+ # "something.jpg" if original_filename
168
+
169
+ # end
170
+
171
+ version :mp3 do
172
+
173
+ process :convert => [{output_format: :mp3}]
174
+
175
+
176
+
177
+ def full_filename(for_file)
178
+
179
+ "#{super.chomp(File.extname(super))}.mp3"
180
+
181
+ end
182
+
183
+ end
184
+
185
+
186
+
187
+ version :wav do
188
+
189
+ process :convert => [{output_format: :wav}]
190
+
191
+
192
+
193
+ def full_filename(for_file)
194
+
195
+ "#{super.chomp(File.extname(super))}.wav"
196
+
197
+ end
198
+
199
+ end
200
+
201
+ end
202
+
203
+ __________________________________________________________________________________
204
+
205
+
206
+
207
+ track.rb
208
+
209
+
210
+
211
+ class Track < ApplicationRecord
212
+
213
+ belongs_to :user
214
+
215
+ mount_uploader :track_image_id, ImagesUploader
216
+
217
+ mount_uploader :track_audio_id, AudioFileUploader
218
+
219
+ has_many :favorites, dependent: :destroy
220
+
221
+
222
+
223
+ with_options presence: true do
224
+
225
+ validates :title
226
+
227
+ validates :description
228
+
229
+ validates :track_image_id
230
+
231
+ validates :track_audio_id
232
+
233
+ end
234
+
235
+
236
+
237
+ end
80
238
 
81
239
  ________________________________________________________________________________
82
240
 
83
- audio_file_uploader.rb
84
-
85
-
86
-
87
- class AudioFileUploader < CarrierWave::Uploader::Base
88
-
89
- # Include RMagick or MiniMagick support:
90
-
91
- # include CarrierWave::RMagick
92
-
93
- # include CarrierWave::MiniMagick
94
-
95
- include CarrierWave::Audio
96
-
97
-
98
-
99
- # Choose what kind of storage to use for this uploader:
100
-
101
- storage :file
102
-
103
- # storage :fog
104
-
105
-
106
-
107
- # Override the directory where uploaded files will be stored.
108
-
109
- # This is a sensible default for uploaders that are meant to be mounted:
110
-
111
- def store_dir
112
-
113
- "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
114
-
115
- end
116
-
117
-
118
-
119
- # Provide a default URL as a default if there hasn't been a file uploaded:
120
-
121
- # def default_url(*args)
122
-
123
- # # For Rails 3.1+ asset pipeline compatibility:
124
-
125
- # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
126
-
127
- #
128
-
129
- # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
130
-
131
- # end
132
-
133
-
134
-
135
- # Process files as they are uploaded:
136
-
137
- # process scale: [200, 300]
138
-
139
- #
140
-
141
- # def scale(width, height)
142
-
143
- # # do something
144
-
145
- # end
146
-
147
-
148
-
149
- # Create different versions of your uploaded files:
150
-
151
- # version :thumb do
152
-
153
- # process resize_to_fit: [50, 50]
154
-
155
- # end
156
-
157
-
158
-
159
- # Add a white list of extensions which are allowed to be uploaded.
160
-
161
- # For images you might use something like this:
162
-
163
- # def extension_whitelist
164
-
165
- # %w(jpg jpeg gif png)
166
-
167
- # end
168
-
169
-
170
-
171
- # Override the filename of the uploaded files:
172
-
173
- # Avoid using model.id or version_name here, see uploader/store.rb for details.
174
-
175
- # def filename
176
-
177
- # "something.jpg" if original_filename
178
-
179
- # end
180
-
181
- version :mp3 do
182
-
183
- process :convert => [{output_format: :mp3}]
184
-
185
-
186
-
187
- def full_filename(for_file)
188
-
189
- "#{super.chomp(File.extname(super))}.mp3"
190
-
191
- end
192
-
193
- end
194
-
195
-
196
-
197
- version :wav do
198
-
199
- process :convert => [{output_format: :wav}]
200
-
201
-
202
-
203
- def full_filename(for_file)
204
-
205
- "#{super.chomp(File.extname(super))}.wav"
206
-
207
- end
208
-
209
- end
210
-
211
- end
212
-
213
- __________________________________________________________________________________
214
-
215
-
216
-
217
- track.rb
218
-
219
-
220
-
221
- class Track < ApplicationRecord
222
-
223
- belongs_to :user
224
-
225
- mount_uploader :track_image_id, ImagesUploader
226
-
227
- mount_uploader :track_audio_id, AudioFileUploader
228
-
229
- has_many :favorites, dependent: :destroy
230
-
231
-
232
-
233
- with_options presence: true do
234
-
235
- validates :title
236
-
237
- validates :description
238
-
239
- validates :track_image_id
240
-
241
- validates :track_audio_id
242
-
243
- end
244
-
245
-
246
-
247
- end
248
-
249
- ________________________________________________________________________________
250
-
251
241
  ### 試したこと
252
242
 
253
243
 
@@ -262,10 +252,8 @@
262
252
 
263
253
 
264
254
 
265
-
266
-
267
- ### 補足情報(FW/ツールのバージョンなど)
255
+ ### 補足情報(FW/ツールのバージョンなど)```ここに言語を入力
268
-
269
-
270
-
256
+
271
- ここにより詳細な情報を記載してください。
257
+ コード
258
+
259
+ ```