質問編集履歴
4
変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[Rails]gem carrierwaveの_cacheができません。
|
1
|
+
[Rails] gem carrierwaveのimage_cacheができません。
|
test
CHANGED
File without changes
|
3
修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[Rails]carrierwaveの
|
1
|
+
[Rails]gem carrierwaveの_cacheができません。
|
test
CHANGED
File without changes
|
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -332,187 +332,7 @@
|
|
332
332
|
|
333
333
|
end
|
334
334
|
|
335
|
-
|
335
|
+
|
336
|
-
|
337
|
-
devise_group :blogger, contains: [:user, :admin]
|
338
|
-
|
339
|
-
before_action :authenticate_admin!, only: [:new, :create, :edit, :update, :destroy]
|
340
|
-
|
341
|
-
before_action :set_blog, only: [:show, :edit, :update, :destroy]
|
342
|
-
|
343
|
-
before_action :set_admin, only: [:show, :create, :edit, :update, :destroy]
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
# GET /blogs
|
348
|
-
|
349
|
-
# GET /blogs.json
|
350
|
-
|
351
|
-
def index
|
352
|
-
|
353
|
-
#@blogs = Blog.includes(:blog_photos).all
|
354
|
-
|
355
|
-
@q = Blog.includes(:blog_photos).ransack(params[:q])
|
356
|
-
|
357
|
-
@blogs_count = @q.result.count
|
358
|
-
|
359
|
-
@blogs = @q.result.page(params[:page]).per(25).order(id: :desc)
|
360
|
-
|
361
|
-
end
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
# GET /blogs/1
|
366
|
-
|
367
|
-
# GET /blogs/1.json
|
368
|
-
|
369
|
-
def show
|
370
|
-
|
371
|
-
@blog_photos = @blog.blog_photos.all
|
372
|
-
|
373
|
-
@blogcomments = @blog.blogcomments.includes(:admin, :user).all
|
374
|
-
|
375
|
-
@blogcomment = @blog.blogcomments.build(admin_id: current_admin.id) if admin_signed_in?
|
376
|
-
|
377
|
-
@blogcomment = @blog.blogcomments.build(user_id: current_user.id) if user_signed_in?
|
378
|
-
|
379
|
-
impressionist(@blog, nil, :unique => [:session_hash])
|
380
|
-
|
381
|
-
end
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
# GET /blogs/new
|
386
|
-
|
387
|
-
def new
|
388
|
-
|
389
|
-
@blog = Blog.new
|
390
|
-
|
391
|
-
@blog_photo = @blog.blog_photos.build
|
392
|
-
|
393
|
-
end
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
# GET /blogs/1/edit
|
398
|
-
|
399
|
-
def edit
|
400
|
-
|
401
|
-
@blog.image.cache! unless @blog.image.blank?
|
402
|
-
|
403
|
-
end
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
# POST /blogs
|
408
|
-
|
409
|
-
# POST /blogs.json
|
410
|
-
|
411
|
-
def create
|
412
|
-
|
413
|
-
@blog = current_admin.blogs.build(blog_params) if admin_signed_in?
|
414
|
-
|
415
|
-
if @blog.save
|
416
|
-
|
417
|
-
params[:blog_photos]['photo'].each do |p|
|
418
|
-
|
419
|
-
@blog_photo = @blog.blog_photos.create!(:photo => p, :blog_id => @blog.id)
|
420
|
-
|
421
|
-
end
|
422
|
-
|
423
|
-
redirect_to @blog, notice: 'ブログが投稿されました'
|
424
|
-
|
425
|
-
else
|
426
|
-
|
427
|
-
render new , notice: "投稿にエラーがありました"
|
428
|
-
|
429
|
-
end
|
430
|
-
|
431
|
-
end
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
# PATCH/PUT /blogs/1
|
436
|
-
|
437
|
-
# PATCH/PUT /blogs/1.json
|
438
|
-
|
439
|
-
def update
|
440
|
-
|
441
|
-
if @blog.update(blog_params)
|
442
|
-
|
443
|
-
redirect_to @blog, notice: 'ブログが更新されました'
|
444
|
-
|
445
|
-
else
|
446
|
-
|
447
|
-
render edit , notice: "更新にエラーがありました"
|
448
|
-
|
449
|
-
end
|
450
|
-
|
451
|
-
end
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
# DELETE /blogs/1
|
456
|
-
|
457
|
-
# DELETE /blogs/1.json
|
458
|
-
|
459
|
-
def destroy
|
460
|
-
|
461
|
-
@blog.destroy
|
462
|
-
|
463
|
-
respond_to do |format|
|
464
|
-
|
465
|
-
format.html { redirect_to @admin, notice: 'ブログを削除しました' }
|
466
|
-
|
467
|
-
format.json { head :no_content }
|
468
|
-
|
469
|
-
end
|
470
|
-
|
471
|
-
end
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
private
|
476
|
-
|
477
|
-
# Use callbacks to share common setup or constraints between actions.
|
478
|
-
|
479
|
-
def set_blog
|
480
|
-
|
481
|
-
@blog = Blog.find(params[:id])
|
482
|
-
|
483
|
-
end
|
484
|
-
|
485
|
-
def set_admin
|
486
|
-
|
487
|
-
@admin = Admin.find_by(params[:admin_id])
|
488
|
-
|
489
|
-
end
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
def correct_admin
|
494
|
-
|
495
|
-
article = Article.find(params[:id])
|
496
|
-
|
497
|
-
if !current_admin?(article.admin)
|
498
|
-
|
499
|
-
redirect_to root_path, alert: '許可されていないページです'
|
500
|
-
|
501
|
-
end
|
502
|
-
|
503
|
-
end
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
# Never trust parameters from the scary internet, only allow the white list through.
|
508
|
-
|
509
|
-
def blog_params
|
510
|
-
|
511
|
-
params.require(:blog).permit(:title, :image, :image_cache, :admin_id, :content, blog_photos_attributes: [:id, :blog_id, :photo])
|
512
|
-
|
513
|
-
end
|
514
|
-
|
515
|
-
end
|
516
336
|
|
517
337
|
|
518
338
|
|
1
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -520,4 +520,34 @@
|
|
520
520
|
|
521
521
|
|
522
522
|
|
523
|
+
uploader.rb
|
524
|
+
|
525
|
+
```ここに言語を入力
|
526
|
+
|
527
|
+
def filename
|
528
|
+
|
529
|
+
"#{secure_token}.png" if original_filename.present?
|
530
|
+
|
531
|
+
#super.gsub!(/[\[\]\"]/, "").gsub!(/,/, "\n")
|
532
|
+
|
533
|
+
end
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
protected
|
540
|
+
|
541
|
+
def secure_token
|
542
|
+
|
543
|
+
var = :"@#{mounted_as}_secure_token"
|
544
|
+
|
545
|
+
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
|
546
|
+
|
547
|
+
end
|
548
|
+
|
549
|
+
```
|
550
|
+
|
551
|
+
|
552
|
+
|
523
553
|
何卒よろしくお願いします。
|