我正在创建图库的应用程序,用于存储照片和相册。我从以下网站获得了帮助:Multiple image upload with carrierwave
但我面临
的错误AlbumPhotosController中的TypeError#创建没有将nil隐式转换为String
这是我的控制器代码:
def create
@album_photo = AlbumPhoto.new(album_photo_params)
respond_to do |format|
if @album_photo.save
format.html { redirect_to @album_photo, notice: 'Album photo was successfully created.' }
format.json { render :show, status: :created, location: @album_photo }
else
format.html { render :new }
format.json { render json: @album_photo.errors, status: :unprocessable_entity }
end
end
end
def album_photo_params
params.require(:album_photo).permit(:album_id,{albumphotos: []})
end
这是我的模特:
#AlbumPhoto Model
class AlbumPhoto < ActiveRecord::Base
belongs_to :album
mount_uploader :albumphotos, AlbumphotoUploader
end
#Album Model
class Album < ActiveRecord::Base
belongs_to :gallery
has_many :album_photos
end
这是我的观点:
<%= form_for(@album_photo) do |f| %>
<div class="field">
<%= f.file_field :albumphotos, multiple: true %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>