いつもお世話になります。
下記サイトを参考にCarrierWaveで複数の画像を保存しようとしているのですがエラーが出てしまいます。公式サイトにも同じ方法が載っていたのでどこかに問題があるとは思うのですが、なかなか解決できずにこちらに質問させていただきました。
エラーはコントローラ側の
@post = Post.new(post_params)
の行で
TypeError (no implicit conversion of nil into String):
というエラーです。
ビュー側のmultiple: trueをfalseにし、POSTするデータを一つだけとすれば、コントローラ側を
params.permit(:poster_name, :post_text, :post_image)
として、普通にデータを保存することができる状態です。
データベースにSqLiteを使っているためJSON型のカラムを使用できないためstring形式としています。
不勉強で申し訳ございませんが、ご教示のほどお願いいたします。
参考サイト
https://qiita.com/ggtmtmgg/items/ba5f275c122c83013ea1
carrierwave公式
https://github.com/carrierwaveuploader/carrierwave#adding-versions
Ruby
1#エラー内容 2 3TypeError (no implicit conversion of nil into String): 4 5 6#コントローラー側 7 8 def update 9 @post = Post.new(post_params) 10 @post.save 11 end 12 def post_params 13 params.permit(:poster_name, :post_text, {post_image: []}) 14 end 15 16 17 18#ビュー側 19 20<%= form_with(model: @user_info, local: true, html: {id: 'inform_save', class: 'form', autocomplete: 'off'}) do |f| %> 21 <div class="field"> 22 <%= f.label :poster_name, "投稿者名" %> 23 <%= f.text_field :poster_name, size: 25, value: "", id: "poster_name", class: "poster_name" %> 24 </div> 25 <div class="field"> 26 <%= f.label :post_text, "投稿内容" %> 27 <%= f.text_field :post_text, size: 25, value: "", id: "post_text", class: "post_text" %> 28 </div> 29 <div class="field"> 30 <%= f.label :post_image %> 31 <%= f.file_field :post_image, multiple: true, class: 'post_image', id: :post_image %> 32 </div> 33 <div class="actions"> 34 <%= f.submit '送信' %> 35 </div> 36<% end %> 37 38 39 40#モデル側 41 42mount_uploader :post_image, ImagesUploader 43serialize :post_image, JSON 44
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。