AlbumPhotosController#中的TypeError没有创建nil到String的隐式转换

时间:2016-04-09 06:12:57

标签: ruby-on-rails ruby carrierwave

我正在创建图库的应用程序,用于存储照片和相册。我从以下网站获得了帮助: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 %>

1 个答案:

答案 0 :(得分:0)

看起来你有一个拼写错误,mount_uploader应该是mount_uploaders(来自tutorial sample code