让carrierwave工作的麻烦

时间:2011-03-20 14:25:41

标签: ruby-on-rails carrierwave

我不确定图片上传是不是保存,还是我将它们保存在错误的地方或出了什么问题..现在我用这段代码生成图像标签时:

<%= image_tag @photo.image_url.to_s %>

它只会引发路由错误:

No route matches "/images"
我想设置这条路线吗?我正在关注railscasts.org 无论如何,这里有一些更相关的代码:

<%= form.file_field :image %> #in the form

mount_uploader :image, ImageUploader  #in the model Photo

#in the image_uploader file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

#also nothing special going on in the controller
def create
@photo = Photo.new(params[:photo])

respond_to do |format|
  if @photo.save
    format.html { redirect_to(@photo, :notice => 'Photo was successfully created.') }
    format.xml  { render :xml => @photo, :status => :created, :location => @photo }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @photo.errors, :status => :unprocessable_entity }
  end
end
end

1 个答案:

答案 0 :(得分:2)

好的,这就是我如何解决它...我认为这是自动的,但事实并非如此。

#in create method and update method and you good :]
@photo.image = params[:file]