使载波正常工作时遇到问题
我不确定图像上传是否未保存,或者我是否将它们保存在错误的位置或出了什么问题..现在当我使用此代码生成图像标签时:
<%= 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
I am not sure if the image uploads just aren't saving or if I am saving them in the wrong place or what's wrong.. right now when I generate the image tag with this code:
<%= image_tag @photo.image_url.to_s %>
it just throws a routing error:
No route matches "/images"
am I suppose to set up this route?.. I was following the tut on railscasts.org
anyway here is some more relevant code:
<%= 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这就是我修复它的方法..我以为这是自动的,但事实并非如此。
Ok here's how i fixed it.. I thought this was automatic, but it wasn't.