【问题标题】:Problem viewing photos in Paperclip - routes error在回形针中查看照片时出现问题 - 路线错误
【发布时间】:2010-09-27 07:59:14
【问题描述】:

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

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

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

没有图像显示。当我转到图片的直接网址时,我得到:

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| %>

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

Processing 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>" }

【问题讨论】:

  • 要检查的三件事:您的回形针设置中是否定义了 :medium 尺寸?图像在给定路径上吗?你重启服务器了吗?
  • 你能展示一下你开发服务器的所有调试吗?
  • @dombesz - :medium 在设置中定义,图像在正确的位置,我已经重新启动了服务器。 :)
  • @tommasop - 我已经添加了上面的数据。谢谢
  • 你能出示has_attached_file声明吗?

标签: ruby-on-rails routes paperclip rmagick


【解决方案1】:

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

代替:

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

应该是:

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

【讨论】:

    【解决方案2】:

    我在使用“webrick”服务器时遇到了这个错误。我检查了我的“公共/系统”文件夹上的所有文件访问权限,它们是正常的。

    最后我切换到 apache/passenger,它工作正常,图像显示正确。

    【讨论】:

      猜你喜欢
      • 2014-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-29
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      相关资源
      最近更新 更多