在回形针中查看照片时出现问题 - 路线错误

发布于 2024-09-25 05:03:01 字数 1204 浏览 6 评论 0原文

我已在系统上成功设置 Paperclip 和 ImageMagick,并且文件正在正确上传、调整大小并保存到正确的文件夹中。

我尝试在我的视图中显示这些图像:

<%= image_tag @customer.logo.url(:medium) %>

没有显示图像。当我访问图像的直接 url 时,我得到:

Routing Error
No route matches "/images/assets/logos/1/medium/corplogo.jpg" with {:method=>:get}

这是一个仍在开发中并在 Windows 上运行的本地服务器。我的表单是多部分的:

<% form_for @customer, :url => {:action => "update", :id => @customer}, :html => {:multipart => true, :id => "myform"} do |f| %>

------ 开发服务器 ------

处理 ApplicationController#index (for 127.0.0.1 at 2010-09-27 04:38:33) [G 东部] 参数:{“1285570273”=>nil}

ActionController::RoutingError(没有路由与“/images/assets/logos/1/medium/corplogo.jpg”与{:method=>:get}匹配): haml (3.0.15)rails/./lib/sass/plugin/rack.rb:41:in `call'

渲染救援/布局 (not_found)

------ 模型 ------

has_attached_file :logo,
    :url => "assets/logos/:id/:style/:basename.:extension",
    :path => ":rails_root/public/assets/logos/:id/:style/:basename.:extension",
    :styles => {:medium => "300x300>", :thumb => "100x100>" }

I have set up Paperclip and ImageMagick successfully on my system, and files are uploading correctly, being resized, and and being saved into the right folders.

I try to display those images in my view:

<%= image_tag @customer.logo.url(:medium) %>

No image is displayed. When I go to the image's direct url I get:

Routing Error
No route matches "/images/assets/logos/1/medium/corplogo.jpg" with {:method=>:get}

This is a local server still in development and running on Windows. My forms are multipart:

<% form_for @customer, :url => {:action => "update", :id => @customer}, :html => {:multipart => true, :id => "myform"} do |f| %>

------ Dev Server ------

Processing ApplicationController#index (for 127.0.0.1 at 2010-09-27 04:38:33) [G
ET]
Parameters: {"1285570273"=>nil}

ActionController::RoutingError (No route matches "/images/assets/logos/1/medium/corplogo.jpg" with {:method=>:get}):
haml (3.0.15) rails/./lib/sass/plugin/rack.rb:41:in `call'

Rendering rescues/layout (not_found)

------ Model ------

has_attached_file :logo,
    :url => "assets/logos/:id/:style/:basename.:extension",
    :path => ":rails_root/public/assets/logos/:id/:style/:basename.:extension",
    :styles => {:medium => "300x300>", :thumb => "100x100>" }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

一桥轻雨一伞开 2024-10-02 05:03:01

我找到了问题的答案,它在于模型中的 url 声明。

而不是:

:url => "assets/logos/:id/:style/:basename.:extension"

应该是:

:url => "/assets/logos/:id/:style/:basename.:extension"

I found the answer to the problem, and it lies with the url declaration in the model.

Instead of:

:url => "assets/logos/:id/:style/:basename.:extension"

it should be:

:url => "/assets/logos/:id/:style/:basename.:extension"
依 靠 2024-10-02 05:03:01

我使用“webrick”服务器时遇到此错误。我检查了“public/system”文件夹上的所有文件访问权限,它们都是正常的。

最后我切换到 apache/passenger,它有效,图像显示正确。

I got this error using the "webrick" server. and I check all the file access permission on my "public/system" folder, they are normal.

finally I switched to apache/passenger, it works, the images are displayed correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文