使载波正常工作时遇到问题

发布于 2024-10-24 15:50:32 字数 994 浏览 4 评论 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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

任性一次 2024-10-31 15:50:32

好吧,这就是我修复它的方法..我以为这是自动的,但事实并非如此。

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

Ok here's how i fixed it.. I thought this was automatic, but it wasn't.

#in create method and update method and you good :]
@photo.image = params[:file]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文