- 浏览: 58875 次
- 性别:
- 来自: 深圳
最新评论
参考了下"rails漫步"的日志,自己也实践了下,下面的问题差不多都遇到了,为此记录下:
1.下载,安装:
a.命令安装:ruby script/plugin install http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk
b.直接安装:把压缩包解压到/vender/plugins/file_column文件夹下即可完成安装(file-column-0.3.1.tar.gz)(我采用的方式)
2.使用方法 :
a.ruby script/generate scaffold entry image:string
b.在Model中,加入
class Entry < ActiveRecord::Base
file_column :image
end
1).Rails2.3安装该插件,报错如下:
uninitializedconstant FileColumn::ClassMethods::Inflector
解决办法:找到 \plugins\file_column\lib\file_column.rb
找到如下代码:
my_options = FileColumn::init_options(options, Inflector.underscore(self.name).to_s, attr.to_s)
修改为:
my_options = FileColumn::init_options(options, ActiveSupport::Inflector.underscore(self.name).to_s, attr.to_s)
2).file_column上传大写后缀名文件报错的解决办法
编辑file_column.rb文件
把:FileUtils.mv(local_file_path, new_local_file_path) unless new_local_file_path == local_file_path
修改成:FileUtils.mv(local_file_path, new_local_file_path) unless new_local_file_path.downcase == local_file_path.downcase
3).file_column上传中文文件名的文件时,汉字变成“_”的解决办法
注释掉file_column.rb文件 把方法 self.sanitize_filename(filename)中的 filename.gsub!(/[^a-zA-Z0-9\.\-\+_]/,"_")
但有的中文就会发生Invalid argument - ./public/entry/image/tmp/的错误。
整理一下,关于File_column+RMagick实际应用中的一些小技巧:
仅允许上传图片:
在类文件中的声明:
file_column :image, :magick => {
:attributes => { :format => ‘jpg’ },
:crop => ‘1:1′,
:versions => { “medium” => “120×120>” , “thumb” => “50×50″}
}
4.页面上使用url_for_file_column显示图片时报错
在页面时使用url_for_file_column helper方法显示图片时报“undefined method `relative_url_root' for #”错误,在网上找个下原因,将
file_column_helper.rb中" url << @request.relative_url_root.to_s << "/" ”改为“url << ActionController::Base.relative_url_root.to_s << "/" "就可以了”,还不清楚为什么。
“thumb” => “50×50″ : 表示如果宽度大则宽度为50如果高度大则高度为50,
“thumb” => “50×50!” : “!”表示强制50*50
“thumb” => “50×50>” : “>”表示如果图片本来就小,就不用放大
“thumb” => “50x>” : 默认宽度为50,高度自适应
Processing EntriesController#create (for 127.0.0.1 at 2011-02-28 18:13:52) [POST]
Parameters: {"commit"=>"Create", "authenticity_token"=>"68zeIrxBMEozxKGyd03LPTt+HpIfDf0yoHhihVCmC7A=", "entry"=>{"image_temp"=>"", "image"=>#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart.4980.0>}}
Entry Columns (4.0ms) SHOW FIELDS FROM `entries`
SQL (1.0ms) BEGIN
Entry Create (1.0ms) INSERT INTO `entries` (`updated_at`, `image`, `created_at`) VALUES('2011-02-28 10:13:52', '___3.jpg', '2011-02-28 10:13:52')
SQL (35.0ms) COMMIT
Redirected to http://localhost:3000/entries/6
Processing EntriesController#create (for 127.0.0.1 at 2011-03-01 13:13:15) [POST]
Parameters: {"commit"=>"Create", "authenticity_token"=>"tK+oWZmp5psq59wGqUmcEMYxS2Uj5cfkwwubrP+Lixs=", "entry"=>{"image_temp"=>"1298956337.684000.3488/rails.png", "image"=>#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart.3488.1>}}
require 'action_controller'
=> []
require 'action_controller/test_process.rb'
=> []
ActionController::TestUploadedFile.new("#{RAILS_ROOT}/public/images/rails.png", 'image/png', false)
=> #<ActionController::TestUploadedFile:0x641a0f4 @content_type="image/png", @original_filename="rails.png", @tempfile=#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/rails.png.3160.0>>
Tempfile.new("rails.png")
=> #<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/rails.png.3160.1>
Processing A::PhotosController#create (for 127.0.0.1 at 2011-03-01 14:39:03) [POST]
Parameters: {"public"=>"true", "uploaded_data"=>#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart1440-3>}
User Columns (6.0ms) SHOW FIELDS FROM `users`
User Load (1.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 2) LIMIT 1
------#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart1440-3>---------------------------!!
------C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart1440-3---------------------------!!
------#<ActionController::TestUploadedFile:0x119235f4 @tempfile=#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart1440-31440-0>, @content_type="image/jpg", @original_filename="RackMultipart1440-3">-------------
参考地址:http://hi.baidu.com/kenrome/blog/item/dedd2f97bec8836554fb9674.html
http://hi.baidu.com/kenrome/blog/item/f40c5de747c8ad2db9382099.html
http://airport.iteye.com/blog/33216
1.下载,安装:
a.命令安装:ruby script/plugin install http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk
b.直接安装:把压缩包解压到/vender/plugins/file_column文件夹下即可完成安装(file-column-0.3.1.tar.gz)(我采用的方式)
2.使用方法 :
a.ruby script/generate scaffold entry image:string
b.在Model中,加入
class Entry < ActiveRecord::Base
file_column :image
end
1).Rails2.3安装该插件,报错如下:
uninitializedconstant FileColumn::ClassMethods::Inflector
解决办法:找到 \plugins\file_column\lib\file_column.rb
找到如下代码:
my_options = FileColumn::init_options(options, Inflector.underscore(self.name).to_s, attr.to_s)
修改为:
my_options = FileColumn::init_options(options, ActiveSupport::Inflector.underscore(self.name).to_s, attr.to_s)
2).file_column上传大写后缀名文件报错的解决办法
编辑file_column.rb文件
把:FileUtils.mv(local_file_path, new_local_file_path) unless new_local_file_path == local_file_path
修改成:FileUtils.mv(local_file_path, new_local_file_path) unless new_local_file_path.downcase == local_file_path.downcase
3).file_column上传中文文件名的文件时,汉字变成“_”的解决办法
注释掉file_column.rb文件 把方法 self.sanitize_filename(filename)中的 filename.gsub!(/[^a-zA-Z0-9\.\-\+_]/,"_")
但有的中文就会发生Invalid argument - ./public/entry/image/tmp/的错误。
整理一下,关于File_column+RMagick实际应用中的一些小技巧:
仅允许上传图片:
在类文件中的声明:
file_column :image, :magick => {
:attributes => { :format => ‘jpg’ },
:crop => ‘1:1′,
:versions => { “medium” => “120×120>” , “thumb” => “50×50″}
}
4.页面上使用url_for_file_column显示图片时报错
在页面时使用url_for_file_column helper方法显示图片时报“undefined method `relative_url_root' for #”错误,在网上找个下原因,将
file_column_helper.rb中" url << @request.relative_url_root.to_s << "/" ”改为“url << ActionController::Base.relative_url_root.to_s << "/" "就可以了”,还不清楚为什么。
“thumb” => “50×50″ : 表示如果宽度大则宽度为50如果高度大则高度为50,
“thumb” => “50×50!” : “!”表示强制50*50
“thumb” => “50×50>” : “>”表示如果图片本来就小,就不用放大
“thumb” => “50x>” : 默认宽度为50,高度自适应
Processing EntriesController#create (for 127.0.0.1 at 2011-02-28 18:13:52) [POST]
Parameters: {"commit"=>"Create", "authenticity_token"=>"68zeIrxBMEozxKGyd03LPTt+HpIfDf0yoHhihVCmC7A=", "entry"=>{"image_temp"=>"", "image"=>#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart.4980.0>}}
Entry Columns (4.0ms) SHOW FIELDS FROM `entries`
SQL (1.0ms) BEGIN
Entry Create (1.0ms) INSERT INTO `entries` (`updated_at`, `image`, `created_at`) VALUES('2011-02-28 10:13:52', '___3.jpg', '2011-02-28 10:13:52')
SQL (35.0ms) COMMIT
Redirected to http://localhost:3000/entries/6
Processing EntriesController#create (for 127.0.0.1 at 2011-03-01 13:13:15) [POST]
Parameters: {"commit"=>"Create", "authenticity_token"=>"tK+oWZmp5psq59wGqUmcEMYxS2Uj5cfkwwubrP+Lixs=", "entry"=>{"image_temp"=>"1298956337.684000.3488/rails.png", "image"=>#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart.3488.1>}}
require 'action_controller'
=> []
require 'action_controller/test_process.rb'
=> []
ActionController::TestUploadedFile.new("#{RAILS_ROOT}/public/images/rails.png", 'image/png', false)
=> #<ActionController::TestUploadedFile:0x641a0f4 @content_type="image/png", @original_filename="rails.png", @tempfile=#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/rails.png.3160.0>>
Tempfile.new("rails.png")
=> #<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/rails.png.3160.1>
Processing A::PhotosController#create (for 127.0.0.1 at 2011-03-01 14:39:03) [POST]
Parameters: {"public"=>"true", "uploaded_data"=>#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart1440-3>}
User Columns (6.0ms) SHOW FIELDS FROM `users`
User Load (1.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 2) LIMIT 1
------#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart1440-3>---------------------------!!
------C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart1440-3---------------------------!!
------#<ActionController::TestUploadedFile:0x119235f4 @tempfile=#<File:C:/Users/FYT~1.SAF/AppData/Local/Temp/RackMultipart1440-31440-0>, @content_type="image/jpg", @original_filename="RackMultipart1440-3">-------------
参考地址:http://hi.baidu.com/kenrome/blog/item/dedd2f97bec8836554fb9674.html
http://hi.baidu.com/kenrome/blog/item/f40c5de747c8ad2db9382099.html
http://airport.iteye.com/blog/33216
发表评论
-
Diaspora 功能特性列表
2013-05-10 14:25 987Diaspora Function Features List ... -
rails scaffold getting the column list from existing table
2011-09-23 10:02 888之前一直找这个问题的解决办法,但一直没找到,在g上看到了一个人 ... -
ruby语法-传值
2011-08-23 16:49 1029=begin def test1(*a) p a.firs ... -
Rails 3 用 JQuery 替代 Prototype
2011-07-28 22:48 11091.进入到工程目录中修改Gemfile文件,加入如下行: g ... -
Generate a list of Rails controllers and methods
2011-07-01 17:40 836列出项目中的controler和他对应的actions: @c ... -
Ubuntu手动安装JDK
2011-05-20 16:03 547Ubuntu手动安装JDK 安装前可以查看一下jdk版本,进 ... -
bundler
2011-04-25 12:12 810Rails3里多了个Bundler工具。 它是一个Librar ... -
研究小计1
2011-04-20 00:55 643有时候对一些基础的东西,不知道它的边界在哪里,其实做些小实验就 ... -
RubyGem version error: rack(1.0.0 not ~> 1.0.1)
2011-04-17 00:09 1338I have this error when I try to ... -
rubyonrails Restful Authentication 插件
2011-04-17 00:01 791restful_authentication是Rails的一个 ... -
XP.CMD命令大全
2011-04-17 00:00 616有关某个命令的详细信 ... -
几个有用的方法
2011-04-16 23:58 569hash.invert Returns a new hash ... -
Firefox键盘快捷方式
2011-04-16 23:55 1195Firefox键盘快捷方式 键盘快捷健 下面是 Mozil ... -
Ubuntu手动安装JDK
2011-04-16 23:53 714Ubuntu手动安装JDK 安装前可以查看一下jdk版本,进 ... -
字符转时间格式转换成时间对象
2011-04-16 23:52 729Time.parse("Wed, 23 Jan 20 ... -
使用Rails时遇到了服务器启动问题 script/server:3
2011-04-16 23:47 1267境 Windows Vista Home Premium c ... -
DoDirectPayment
2011-04-16 23:44 984DoDirectPayment 1. DoDirectPay ... -
Rails异常处理
2011-04-16 23:43 953异常处理是开发过程中 ... -
ruby和rails中的回调函数
2011-04-16 23:41 1866Ruby中Class,Object,Module这三个类定义了 ... -
深入理解alias, alias_method和alias_method_chain
2011-04-16 23:41 861对 于alias, alias_method, alias_m ...
相关推荐
File_System_Auditor文件系统审计软件可以实现对共享文件的审计(日志可追溯事件当天),可在Windows Server 2008 R2 64位系统及以上操作系统安装和运行。
用VB写的一个串口文件传送系统,实现了串口之间文件传送的例子。很有参考价值。
文件列表获取和文件获取,适用于MMS IEC 61850通信服务
内存映射文件的使用
WinCE下文件系统编程,在WinCE平台下创建文件。
Adobe_Flash_File_Video_Format_Specification_v10_1是adobe flash视频文件格式规范文档,用于描述flv和f4v的文件格式标准规范的文档
文件服务器文件监控审计软件
asp简单文件上传源码 文件1.上传界面文件 upload.htm 文件2.保存上传文件 SaveFile.asp
基于socket的任意文件传输,可以传输任意文件
原文链接:https://blog.csdn.net/m0_37814112/article/details/122538085 说明:基于file_sd_configs部署blackbox-exporter监控k8s服务
用于TM1300/PNX1300系列DSP(主要用于视频处理)的flash文件系统的程序源码。
VC编程实现逐行读取文件经典代码VC programming read the file line by line, the classic code
r ./ha_file_explorer/custom_components/ha_file_explorer custom_components# 删除clone的文件sudo rm -rf ha_file_explorer# 安装依赖pip3 install qiniu asgiref使用方式# 默认配置ha_file_explorer:# 完整配置...
1、设计一个10个用户的文件系统,每次用户可保存10个文件,一次运行用户可以打开5个文件。 2、程序采用二级文件目录(即设置主目录[MFD])和用户文件目录(UED)。另外,为打开文件设置了运行文件目录(AFD)。 3、...
文件传送协议的服务器端和客户端源码,自创的文件通讯协议,对网络服务器和客户端编程有一定的启示
MFC 文件读取 Mfc file read
PhoneGap,API帮助文档翻译整理8-File_(文件)
localfile_1_0_0.dll: %1 不是有效的 Win32 应用程序。替换文件
本文介绍了在php中使用file_get_contents函数读取大文件的方法,并附上了示例以及使用小技巧,非常的实用,这里推荐给大家
video_file_format_spec_v10 标准文件 Adobe Flash Video File Format Specification (Version 10.1) The open F4V/FLV specification documents file format information for storing media content used to ...