Paperclipで画像を複数投稿できるフォームを設定したいのですが、
multiple: trueを設定すると、controller側で値がNillになり、DBでもデータ登録ができておりません。 どなたかフォーム上で複数uploadが可能になる方法をご教授いただければと存じます
バージョン
Rails4
Ruby2.1
Picture model
class Picture < ActiveRecord::Base has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" } validates_attachment :avatar, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] } end
Picture controller
class PicturesController < ApplicationController def index @pictures = Picture.all end def new @picture = Picture.new end def create @picture = Picture.new(picture_params) byebug if @picture.save redirect_to dashboards_path else render 'new' end end private def picture_params params.require(:picture).permit(:name, :photo, :avatar) end end
Picture new.html.slim
= simple_form_for @picture, url: pictures_path do |form| = form.file_field :avatar, as: :file , multiple: true = form.submit "送信"
byebugした際のcreate処理で渡されるパラメーター
11: def create 12: @picture = Picture.new(picture_params) 13: byebug => 14: if @picture.save 15: redirect_to dashboards_path 16: else 17: render 'new' 18: end (byebug) (byebug) @picture #<Picture id: nil, name: nil, string: nil, created_at: nil, updated_at: nil, photo_file_name: nil, photo_content_type: nil, photo_file_size: nil, photo_updated_at: nil, avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/21 23:00
2017/09/22 10:10