路由错误使用Rails 3回形针和S3 [英] Routing Error with Rails 3 Paperclip and S3

查看:178
本文介绍了路由错误使用Rails 3回形针和S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟着本教程完全

的ActionController :: RoutingError(无   路由匹配   /logos/medium/missing.png)

ActionController::RoutingError (No route matches "/logos/medium/missing.png")

我检查了类似的教程,其中没有提到需要为你的远程图像的路线。就像我说的,我已经三检查本教程中,我做的一切要求我的,所以有什么措施可以我可以在这里丢失?唯一的区别是,我已经有了一个二进制数据类型具有相同名称的 has_​​attached_file 变量指定的照片列在我的模型......莫非是造成冲突?

I checked similar tutorials and none of them mentioned requiring routes for your remote images. Like I said, I have triple-checked this tutorial and I'm doing everything it asks of me, so what steps could I be missing here? The ONLY difference is that I already had specified a "photo" column in my model as a binary datatype with the same name as the has_attached_file variable...could that be causing the conflict?

推荐答案

我正要删除时,我意识到这将是有价值的别人学习什么地方出了错。

I was about to delete this when I realized it will be valuable for others to learn what went wrong.

所以,如果你按照教程发球,你会做得很好。但是,如果你使用 attr_accessible 来保护你的模型的属性,你需要指定都掌握在你的模型,以使这些图像实际上是保存到您的S3存储。

So if you follow that tutorial to the tee you will do just fine. HOWEVER, if you use attr_accessible to protect the attributes of your model, you need to specify ALL of them in your model in order to make these images actually save to your S3 bucket.

一个提示会,如果你看到下面的你的日志:

A hint will be if you see the following in your logs:

警告:不能批量分配保护的属性:照片

这让你知道你已经在保护你的数据库列,需要通过 attr_accessible

This lets you know that you have protected columns in your database that need to be exposed through attr_accessible

这里的code会是什么样,如果你按照我在我的问题所提供的实例教程,如:

Here's what the code would look like if you were to follow the example tutorial I provided in my question:

class Product < ActiveRecord::Base
  attr_accessible :photo, :photo_file_name, :photo_content_type, :photo_file_size, :photo_updated_at
  belongs_to :page
  has_attached_file :photo,
    :styles =>{
      :thumb  => "100x100",
      :medium => "200x200",
      :large => "600x400"
    },
    :storage => :s3,
    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
    :path => ":attachment/:id/:style.:extension",
    :bucket => 'yourbucket'
end

这篇关于路由错误使用Rails 3回形针和S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆