vkill'blog

“技术本身没有太多价值,掌握了新的思考方式才是真的收获”
Pages: 1/2 First page 1 2 Next page Final page [ View by Articles | List ]
rails_kindeditor 见这里 https://github.com/Macrow/rails_kindeditor,使用很方便
但是在后台使用的时候每次上传图片就会 session 丢失
看了 post 的参数发现是没有提交 authenticity_token
网上没找到解决方案,没法,只有改js源码了

kindeditor/kindeditor-init.js 是这里定义的 uploadJson: "/kindeditor/upload" ,也就是上传的地址,本想在后面加 ?authenticity_token=xxxx 这样的
但是后面的 kindeditor/plugins/image/image.js 里这样使用了 url : uploadJson + '?dir=image' ,
那么只有改 kindeditor/plugins/image/image.js 了,改成下面这样就ok了

#kindeditor/plugins/image/image.js
url : uploadJson + '?dir=image' + "&" + encodeURIComponent($("[name='csrf-param']").attr("content")) + "=" + encodeURIComponent($("[name='csrf-token']").attr("content")),


ok,就这样解决就好,rails_kindeditor 这个定义 uploadJson 不怎么好,要是定义成 uploadJson: "/kindeditor/upload?" ,image.js 中这样使用 url : uploadJson + '&dir=image' ,这样就好扩展多了
类别:ruby & rails | Tags: , , , , , , , | 1 条评论, 2157 次阅读
Sep
19
2011
Image model 代码如下

# cat app/models/image.rb
class Image < ActiveRecord::Base
  has_attached_file :data,
                    :url  => "/system/images/:id/:style_:basename.:extension",
                    :path => ":rails_root/public/system/images/:id/:style_:basename.:extension",
                    :styles => { :normal => ['400x300#', :png], :thumb => ['200x150#', :png] }

  validates_attachment_size :data, :less_than => 2.megabytes
  validates_attachment_presence :data
end


那么想在 seed 中保存几个图片到 Image,就这样写

# cat db/seeds.rb
#first, add  gem "content_type"  to Gemfile and bundle install, http://rubygems.org/gems/content_type
attachment_file = "#{Rails.root}/public/images/rails.png"
attachment = {
  :original_filename => File.basename(attachment_file),
  :content_type => File.content_type(attachment_file),
  :tempfile => File.open(attachment_file, 'rb')
}
data_obj = ActionDispatch::Http::UploadedFile.new(attachment)
data_obj.original_filename = attachment[:original_filename]
data_obj.content_type = attachment[:content_type]
Image.create!(:data => data_obj)



后记:
使用 fixture_file_upload

include ActionDispatch::TestProcess
Image.create :data => fixture_file_upload("/root/profile.jpg", 'image/jpg')


结合 factory_girl 使用如下

include ActionDispatch::TestProcess
FactoryGirl.define do
  factory :attachment do
      name { Faker::LoremCN.word }
      describtion { Faker::LoremCN.word }
      data { fixture_file_upload(Rails.root.join('public', 'images', 'rails.png'), 'image/png', :binary) }
      download_times { rand 1_000 }
    end
end
类别:ruby & rails | Tags: , , , , , , , , | 0 条评论, 1919 次阅读
Jun
6
2011
rmagick 生成图片时提示 not found /usr/share/fonts/Type1/n0190031.pfb

环境 archlinux ruby1.9.2 ImageMagick6.6.7-1 rmagick2.13.1

在一次使用 rmagick 生成图片的时候碰到了 /usr/share/fonts/Type1/n0190031.pfb未找到 的错误
google 这个错误半天
在官方的安装FAQ http://rmagick.rubyforge.org/install-faq.html 里提到了这个错误
大概意思是说 使用"/usr/share/fonts/default/Type1/a010013l.afm"这个的时候要 --with-gs-font-dir option (and optionally the --with-windows-font-dir option).  

最后 #pacman -Ss gs 后,找到了有 gsfont 包安装了就好了
当然要安装更多的字体的话 #pacman -Ss font 自己找好了

另外如果你需要生成png图片的话,还需要安装 libpng 包

后记:查看 ImageMagick支持哪些字体的话 #convert -list font 查看
类别:linux system | Tags: , , , , , , , | 0 条评论, 1087 次阅读
Feb
12
2011
当使用 require 'RMagick' 的时候,有时候会报如下错误
Quotation

[root@localhost ~]# irb -rubygems -r RMagick
:33:in `require':LoadError: libMagickCore.so.4: cannot open shared object file: No such file or directory - /usr/local/rvm/gems/ruby-1.9.2-p136/gems/rmagick-2.13.1/lib/RMagick2.so


发生这个错误是因为 ImageMagick 默认会安装到 /usr/local/lib,在某些发行版里这个目录里的 lib 不会被加载
那么解决方法是 可以在编译时指定 --prefix=/usr 参数来安装到 /usr/lib 里,也可以装到 /usr/local/lib 后将 libMagick* 符号链接到 /usr/lib 里

ln -s /usr/local/lib/libMagick* /usr/lib


后记:
gem i rmagick 前 除了要安装 ImageMagick 外还要安装开发库 ,ubuntu apt-get install libmagick9-dev,centos yum install ImageMagick-devel

测试 RMagick gem 是否正常安装

ruby -rrubygems -e "require 'RMagick'; puts Magick::Long_version;"
类别:ruby & rails | Tags: , , , , , , , , | 0 条评论, 1098 次阅读
Jan
12
2011
测试环境: ruby 1.8.7 + rails 2.3.5 + paperclip 2.3.6 + RMagick-2.12.0-ImageMagick-6.5.6-8-Q8

具体的使用方法见这篇文章
http://cn.asciicasts.com/episodes/134-paperclip

windows中使用前先做的两件事:
1、因为其他地方还要使用 RMagick ,所以到官方下载安装包来安装
rmagick官方http://rubyforge.org/projects/rmagick/ 网站下载 rmagick-win32 的 binary gem for Ruby 1.8.6 (也适合于1.8.7)
即:http://rubyforge.org/frs/download.php/64917/RMagick-2.12.0-ImageMagick-6.5.6-8-Q8.zip 安装exe后再安装gem 就可以了
另外安装完了后添加到 path ,确保cmd下可执行 identify
2、修改 c:\WINDOWS\system32\convert.exe 为 c:\WINDOWS\system32\_convert.exe ,因为 imagemagick 中 convert 和这冲突

类别:ruby & rails | Tags: , , , , , , , | 0 条评论, 972 次阅读
Dec
5
2010
图片幻灯片式播放

用到的主知识点:
setTimeout()

演示地址:
http://www.vkill.net/demo/image_slide/image_slide.html

网页程序打包下载:
类别:web | Tags: , , , , , | 0 条评论, 1065 次阅读
Nov
8
2008
Pages: 1/2 First page 1 2 Next page Final page [ View by Articles | List ]