2011-03-20 113 views
0

我不确定上传的图像是否不存在,或者我是否将它们保存在错误的地方或者有什么问题..现在,当我使用此代码生成图像标记时:运营商波工作遇到困难

<%= 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 
+0

它创建一个没有问题的对象吗?它只是抛出错误@ photos#show? – 2011-03-20 15:41:18

+0

这是正确的,它并没有显示运行时错误,因为我没有.to_s,但它认为图像为零我猜,但它确实创建一个链接..../images/1823474或w/e – Tyler 2011-03-20 20:12:45

回答

2

好吧这里是我如何修复它..我认为这是自动的,但它不是。

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