Ruby on rails 开车去上班有困难
我不确定上传的图像是否没有保存,或者我是否保存在了错误的位置,或者是什么地方出了问题。。现在,当我使用以下代码生成图像标记时:Ruby on rails 开车去上班有困难,ruby-on-rails,carrierwave,Ruby On Rails,Carrierwave,我不确定上传的图像是否没有保存,或者我是否保存在了错误的位置,或者是什么地方出了问题。。现在,当我使用以下代码生成图像标记时: <%= image_tag @photo.image_url.to_s %> 我应该设置这条路线吗?。。我在跟踪railscasts.org上的图坦卡蒙 无论如何,这里有一些更相关的代码: <%= form.file_field :image %> #in the form mount_uploader :image, ImageUpload
<%= image_tag @photo.image_url.to_s %>
我应该设置这条路线吗?。。我在跟踪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
#在表单中
mount_uploader:模型照片中的图像、图像上传器
#在图像上传程序文件中
def存储目录
“上载/#{model.class.to_s.下划线}/#{mounted_as}/#{model.id}”
结束
#控制器中也没有发生什么特殊情况
def创建
@照片=照片。新建(参数[:照片])
回应待办事项|格式|
如果@photo.save
format.html{redirect_to(@photo,:notice=>“照片已成功创建”)}
format.xml{render:xml=>@photo,:status=>:created,:location=>@photo}
其他的
format.html{render:action=>“new”}
format.xml{render:xml=>@photo.errors,:status=>:unprocessable_entity}
结束
结束
结束
好的,下面是我如何修复它的。。我以为这是自动的,但不是
#in create method and update method and you good :]
@photo.image = params[:file]
它是否创建了一个没有问题的对象?它只是在@photos#show?上抛出了一个错误,这是正确的,而且它没有显示运行时错误,因为我这样做了。对,但它认为图像为零,我猜,但它确实创建了一个链接/图片/1823474或w/e
#in create method and update method and you good :]
@photo.image = params[:file]