FTP用户无法登陆排错详解
2008-04-24 21:40
309 查看
Paperclip 是 Rails 的一个处理 attachment 的插件,相对于以往的 FileColumn 在灵活性和效率上更胜一筹,而且代码也比较好看。这个视频
简单的介绍了 Paperclip 的使用方法。
默认的设置,URL 的占位符中与模型本身相关的只有 id,但是一些情况下,你可能会更希望以其他形式来组织你的附件目录 - 比如以 SKU 来代替数据库记录的 id。这里我们暂不讨论这种做法的好坏,双方面的,好处是目录结构更具有维护性,坏处是万一以后升级数据库,SKU 加个前缀什么的…
Here we go!
使用 paperclip 需要在 model 中调用 has_attached_file
方法,检查文档,有一些简单的使用样例,但是没有我们需要的。通过方法描述我们知道这个方法建立了一个 Paperclip::Attachment 对象,我们继续看文档。对象的方法很少,首先思考:应为我们需要配置的是 attachment 的 url 规则,那么应当是对应整个类而不是单个实力,因此我们只关注 Peperclip::Attachment 的类方法,只有两个。default_options 没有描述,而且展开代码发现并不是我们需要的。
引用
# Paperclip::Attchment.interpolation
A hash of procs that are run during the interpolation of a path or
url. A variable of the format :name will be replaced with the return
value of the proc named “:name”. Each lambda takes the attachment and
the current style as arguments. This hash can be added to with your own
proc if necessary.
这正是我们需要的,接下来的扩展就非常方便了:
在这里不直接使用 :sku 作为占位符而使用 :to_param 是为了在其他模型中更加的灵活。
简单的介绍了 Paperclip 的使用方法。
默认的设置,URL 的占位符中与模型本身相关的只有 id,但是一些情况下,你可能会更希望以其他形式来组织你的附件目录 - 比如以 SKU 来代替数据库记录的 id。这里我们暂不讨论这种做法的好坏,双方面的,好处是目录结构更具有维护性,坏处是万一以后升级数据库,SKU 加个前缀什么的…
Here we go!
使用 paperclip 需要在 model 中调用 has_attached_file
方法,检查文档,有一些简单的使用样例,但是没有我们需要的。通过方法描述我们知道这个方法建立了一个 Paperclip::Attachment 对象,我们继续看文档。对象的方法很少,首先思考:应为我们需要配置的是 attachment 的 url 规则,那么应当是对应整个类而不是单个实力,因此我们只关注 Peperclip::Attachment 的类方法,只有两个。default_options 没有描述,而且展开代码发现并不是我们需要的。
引用
# Paperclip::Attchment.interpolation
A hash of procs that are run during the interpolation of a path or
url. A variable of the format :name will be replaced with the return
value of the proc named “:name”. Each lambda takes the attachment and
the current style as arguments. This hash can be added to with your own
proc if necessary.
这正是我们需要的,接下来的扩展就非常方便了:
# app/models/product.rb class Product < ActiveRecord::Base has_attached_file :photo, :style => { :thumb => '64x64>' }, :url => '/images/products/:to_param.:extension' def to_param return self.sku end end # config/initializers/paperclip.rb Paperclip::Attachment.interpolations.merge!( :to_param => lambda { |attachment, style| attachment.instance.to_param } )
在这里不直接使用 :sku 作为占位符而使用 :to_param 是为了在其他模型中更加的灵活。
相关文章推荐
- FTP用户无法登陆排错详解
- FTP用户无法登录排错详解
- ubuntu_ftp_server配置方法【附root用户无法登陆ftp解决方案】
- AIX系统ftp用户无法登陆问题
- 解决ftp限制用户访问上层目录后无法登陆问题
- CentOS中解决root用户无法登陆ftp传输文件的问题
- FTP用户无法登陆产生原因以及对应解决方法
- vsftpd用户设置成nologin时无法登陆ftp
- CentOS 6.5 vsftp搭建 解决root用户无法登陆ftp传输文件的问题
- ubuntu_ftp_server配置方法【附root用户无法登陆ftp解决方案】
- SQLServer 2005中Sa用户可以登录进去,Windows管理员却无法登陆进去
- Win2003中配置FTP服务,开启防火墙导致客户端无法连接【精华详解】
- linux id命令参数及用法详解(linux查看当前登陆用户uid,gid)
- Mac下安装的MySQL root账号无法登陆用户解决
- user profile service服务未能登陆,无法加载用户配置文件
- 判断vsftpd虚拟用户无法登陆故障方法
- linux上搭建ftp服务器,并设置本地用户登陆。
- [Jenkins]admin用户登陆,提示登陆无效(之前登陆OK,三天没有登陆,突然提示登陆无效,重启无法解决)的解决方法
- $HOME/$user/.权限导致用户无法登陆图形界面
- mysql-用户管理 用户无法本地登陆