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

質問編集履歴

1

コードの最新化

2021/01/04 01:12

投稿

jm_swim
jm_swim

スコア8

title CHANGED
File without changes
body CHANGED
@@ -41,12 +41,19 @@
41
41
  belongs_to :debate
42
42
  belongs_to :user, optional: true
43
43
  belongs_to :coach, optional: true
44
- has_one_attached :image, optional: true
44
+ has_one_attached :image
45
- has_one_attached :video, optional: true
45
+ has_one_attached :video
46
46
 
47
+ comment = Comment.last
48
+ comment.video.attach(
47
- validates :content, presence: true, unless: :was_attached? || :is_attached?
49
+ io: File.open("path/to/video"),
50
+ filename: "video.txt",
48
- validates :image, presence: true, unless: :is_attached?
51
+ content_type: "text/plain"
52
+ )
49
53
 
54
+ validates :content, presence: true, unless: :was_attached?
55
+ validates :content, presence: true, unless: :is_attached?
56
+
50
57
  def was_attached?
51
58
  self.image.attached?
52
59
  end
@@ -55,8 +62,8 @@
55
62
  self.video.attached?
56
63
  end
57
64
 
58
- mount_uploader :video, VideoUploader
59
65
  end
66
+
60
67
  ```
61
68
 
62
69
  ```
@@ -87,24 +94,20 @@
87
94
  @comments = @debate.comments.includes(:user)
88
95
  render :index
89
96
  end
90
- binding.pry
91
97
  end
92
98
 
93
99
  private
94
100
 
95
101
  def coach_comment_params
96
- if coach_signed_in?
97
102
  params.require(:comment).permit(:content, :image, :video).merge(coach_id: current_coach.id)
98
- end
99
103
  end
100
104
 
101
105
  def user_comment_params
102
- if user_signed_in?
103
106
  params.require(:comment).permit(:content, :image, :video).merge(user_id: current_user.id)
104
- end
105
107
  end
106
108
  end
107
109
 
110
+
108
111
  ```
109
112
 
110
113