rubyonrails
w_t_bll
这个作者很懒,什么都没留下…
展开
-
restful_authentication的site_key问题
好久没来写东西了,最近项目太忙,也懒的写啥。不过今天花了两个小时解决了一个很无聊的问题,记一下。restful_authentication是采用随机生成的site_key来加密密码,我们项目在开发过程中经常采用svn加capistrano来修改加部署,这样的话,每次部署后,为了图省事,我们一般用capistrano自动rake auth:gen:site_key,而此时生成的site_key...2009-08-17 02:56:57 · 144 阅读 · 0 评论 -
acts_as_taggable_on_steroids代替原acts_as_taggable
1、安装ruby script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids2、 class Post < ActiveRecord::Base acts_as_taggable end3、p = Post.find(:...2008-04-23 09:45:31 · 107 阅读 · 0 评论 -
ferret+acts_as_ferret+RMMSeg全文索引+中文分词的使用
首先,在ubuntu下要安装atp-get install build-essential zlib1g-devruby需要安装dev包1、安装ferretsudo gem install ferret2、安装acts_as_ferret可用gemsudo gem install acts_as_ferret或用pluginssvn://projects.jkraemer.ne...2008-04-22 13:21:26 · 162 阅读 · 0 评论 -
rails测试驱动开发中的一些知识点滴
def setup @controller=***.new @request=ActionController::TestRequest.new @response=ActionController::TestResponse.newend assert_template 测试是否装载了正确的viewassert_tag 'form',:attributes=>{:acti...2008-04-21 19:28:59 · 99 阅读 · 0 评论 -
升级到snow 10.6 ROR的解决
http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard叁照些文章安装,不过特别要注意的是,要重新编译ruby,因为原来的ruby是32位的,如果你mysql改用64位后,需要编译msyql gem为64位,而此gem是用ruby来跑,所以ruby必须要在新的环境下重新编译一次即可。...2009-10-13 23:25:35 · 92 阅读 · 0 评论 -
ruby console plugin
前几天在看 screencasts,发现一好插件:Hirb 。这是个扩展命令行的插件,可以以更加易读的形式展现方法返回的内容(比如以 mysql 输出的形式展现 ActiveRecord 实例) gem install cldwalker-hirb --source http://gems.github.com/# Append the following lines into...原创 2009-10-12 11:09:49 · 130 阅读 · 0 评论 -
private的一个问题
首先,要明白这几个ruby的原理1、默认(包括你所用的定义方法)在顶层定义的都是private的实例方法2、private方法是不允许指明接收者的,其接收者只能是隐含的selfdef x11puts "in x11"enddef x11=(t) puts tendx11self.x11="ddd"当前定义了两个方法,都是private的,可以puts self.private_methods.s...2008-07-03 15:34:02 · 97 阅读 · 0 评论 -
截取中文
def trc_utf8(text, length = 40, t_string = "...") l=0 char_array=text.unpack("U*") char_array.each_with_index do |c,i| l = l+ (c<127 ? 0.5 : 1) if l>...2008-06-13 21:45:26 · 108 阅读 · 0 评论 -
rails1.2.3的在rubyforge更新到1.0.0以后产生的问题解决
运行时提示已active0.4.5.不能active1.0.0,那直接删除0.4.5的gem就行了。2008-06-17 17:38:17 · 70 阅读 · 0 评论 -
Ruby中闭包与block
转道友Blog中的一小段code说明ruby中的闭包procs = [] (1..3).each do |i| procs << lambda { puts i } end procs.each { |p| p.call } # Output: # 1 # 2 # 3 ########################...2008-06-17 08:01:26 · 129 阅读 · 0 评论 -
memcached+libmemcached+memcache_client
ubuntu下安装memcached非常简单运行也很简单 ./memcached -d -m 2048 -l 10.0.0.40 -p 11211如果要使用caffeine,请参考http://blog.methodmissing.com/2007/6/4/get-your-caffeine-on/本人是使用的 memcache-clientgem install memcache-c...2008-05-02 16:33:01 · 157 阅读 · 0 评论 -
全国省市县三级数据库
中国省,市,县(区)三级数据信息,已转换成mysql的dump文件2008-05-12 22:41:03 · 217 阅读 · 0 评论 -
rjcop处理图片上传时截取
http://github.com/jschwindt/rjcrop/2009-12-21 02:11:34 · 132 阅读 · 0 评论 -
ubuntu下rmagick快速安装(备忘)
sudo apt-get install libmagick9-dev ruby1.8-devsudo gem install rmagicksudo apt-get install imagemagicksudo gem install rmagick2008-12-09 21:54:33 · 117 阅读 · 0 评论 -
关于rails的route的性能
今天跟蛋黄讨论关于route的性能问题,经过跟踪调试发现,具名路由的实现相当简单,并且性能也相当好。在服务器启动时,map.resources会生成相应的路由的对象,比如map.resources :blogs会生成若干个named routes地址的对象比如: edit_blog,对象类型是ActionController::Routing::Route,其中有个to_s...2008-12-05 12:20:10 · 148 阅读 · 0 评论 -
sphinx在ubuntu8.1下安装与使用
参考 dlee 的 http://www.iteye.com/topic/200065在安装mmseg的过程中出错的解决办法以及自己整理一下在ubuntu8.1下的完整安装与使用 g++更换到4.1版本,python使用2.5编译coreseek通过李沫南还开发了一个支持中文全文检索的Sphinx定制版本——Coreseek,除了支持中文的全文检索外,Coreseek最大的特点是支...原创 2008-12-03 21:40:52 · 139 阅读 · 0 评论 -
用ruby抓取gzip网页
require 'net/http'require 'uri'module Net class HTTP def HTTP.get_with_headers(uri,headers=nil) uri=URI.parse(uri) if uri.respond_to? :to_str start(uri.host,uri.port) do |http| re...2008-05-26 19:42:41 · 172 阅读 · 0 评论 -
让url更人性化_acts_as_slugable
== Installation<tt>./script/plugin install http://code.dunae.ca/acts_as_slugable</tt>== Usage examplesIn your target table, add a column to hold the URL slug.=== With scope class Page <...2008-05-26 09:29:11 · 67 阅读 · 0 评论 -
在ror项目中使用paypal
http://www.codyfauser.com/2008/1/17/paypal-express-payments-with-activemerchant2008-05-21 18:18:41 · 63 阅读 · 0 评论 -
由于页面中对代码加亮的JS
http://alexgorbatchev.com/wiki/SyntaxHighlighter原创 2009-11-05 12:57:01 · 92 阅读 · 0 评论 -
git server+continuouse integrity
gem install integrity #安装Integrity gemintegrity install --passenger | --thin Install_PATH #在指点的地点安装integrity程序,passenger及thin是看你的WEB服务器使用哪种然后去Install_PATH中编辑config.yml 主要是看使用何种DBintegrity ...2009-10-28 15:12:26 · 140 阅读 · 0 评论 -
又一个处理图片的插件
http://fleximage.rubyforge.org/examples/ Home: http://fleximage.rubyforge.org/ Repository: svn://rubyforge.org/var/svn/fleximage Effect examples: http://fleximage.rubyforge.org/examples resi...2007-08-30 17:14:12 · 177 阅读 · 0 评论 -
routes笔记
例:ruby 代码map.admin_report 'report/:year', :controller => 'admin', :action => 'report' Having this named route in routes.rb tells Rails to create two ne...2007-08-28 15:22:15 · 102 阅读 · 0 评论 -
在model中插入table的结构(方便编程)
ruby 代码 ruby script/plugin install http://svn.pragprog.com/Public/plugins/annotate_models rake annotate_models2007-06-27 10:15:50 · 183 阅读 · 0 评论 -
ubuntu下使用capistrano时出现缺少openssl的解决
The Ruby OpenSSL bindings are not installed by default on Ubuntu and Capistrano needs them.. so if you see this error:ruby 代码`gem_original_require': no such file to load -- openssl (LoadError) run ...2007-06-24 11:19:52 · 100 阅读 · 0 评论 -
郁闷的下午,郁闷的RMagick
初学ror一星期,过程中一直相安无事,但是昨天被RMagick浪费了我两小时,今天三个小时又被RMagick无情的浪费掉了,贴在这耽误大家一些时间帮忙找找原因,1、用webrick运行的时候,只要我在controller中加入 ruby 代码 require 'RMagick' include Magick 此时只要执行任何action(也就是装载了c...2007-06-14 16:56:25 · 65 阅读 · 0 评论 -
罗列网上的实现方法--rails中使用FCKeditor
1、安装rails的FCKeditor插件 script/plugin install svn://rubyforge.org/var/svn/fckeditorp/trunk/fckeditor如果出现下面的错误:A D:\open_rails\mephisto\trunk\vendor\plugins\fckeditor\public\javascripts\fckedi...2007-06-14 12:05:48 · 96 阅读 · 0 评论 -
关于RMagick在Webrick下无法使用的笨解决方法
费了几个小时,把RMagick库ImageMagick都重装了。结果发现,在Webrick下,无法使用RMagick库。不知道是什么原因。(如果哪位达人知道,请赐教)。不过这次彻底把RMagick方面全装好了。以前装的时候提示不能处理Freetype和ghostscript,原来没装这两个包,在ubuntu下用apt-get也没装成功,后来手工下载安装的。...2007-06-13 14:12:29 · 61 阅读 · 0 评论 -
Robbin的Linux下ROR安装之我的问题及解决
按照Robbin的文章在Linux下安装ruby on rails环境,在我的系统上安装时出了些小问题,以下是出现的问题和解决方法:原文:www.iteye.com/topic/432281、在安装lighttpd的时候,如果要激活mod_rewrite模块,需要pcre(rewrite是根据正则表达式来现实的),系统一般默认安装pcre包,但没有装pcre-devel包,需要自己安装;2...2007-05-26 11:01:45 · 135 阅读 · 0 评论 -
Ruby中的特殊变量、常量
$0 :当前脚本名称$: :动态库路径$& :[正则表达式]与模式匹配的那部分$` :(反引号)[正则表达式]与模式匹配之前的那部分$' :[正则表达式]与模式匹配之后的那部分$~ :[正则表达式]是MatchData对象,它持有有关匹配的所有信息$1...... :[正则表达式]持有匹配各个部分的值$+ :[正则...2007-05-23 14:10:07 · 177 阅读 · 0 评论 -
需要知道Ruby的...
以下都是在资料中摘抄下来的,有的目前还没有理解透,慢慢理解。1、nil是对象(java中null不是对象)2、整数是个完整的对象,如:3.abs3、实例由类自己参建,通用工厂: def create_from_factory(factory) factory.new end obj = create_from_factory(Array) 4、 Method...2007-05-19 10:57:43 · 89 阅读 · 0 评论 -
需要知道Ruby的--Messages, not Function Calls
Messages, not Function Calls Java Programmers tend to think of obj.method() as looking up a member function in a table and calling it. Ruby programmers tend to think of obj.method as sending a mes...2007-05-19 10:04:27 · 86 阅读 · 0 评论 -
rails中的常用分页一
snippets.dzone.com/posts/show/389Sometimes it's nearly impossible to paginate a result set using the built-in :limit and :offset parameters of find(:all). Instead, you can fetch a complicated query ...2007-06-27 11:39:05 · 201 阅读 · 0 评论 -
form_tag的小问题
<%form_tag ({:action => 'update',:id => @photo}, :multipart=> true ) do %>要加上小括号,和大括号,否则,处理有错,另外参数顺序不能错了。,原因在于形参是*方式接受。唉,有时语言太灵活了也痛苦呀,呵呵。虽然这很简单,手册中也有详细的信息。但还是记下来,因为,ruby/rails中经常因此产生...2007-06-30 20:18:28 · 279 阅读 · 0 评论 -
validations常用方法
ruby 代码 validates_inclusion_of :class_level, :in => %w( Freshmen Sophomore Junior Senior), :message=>"must be: Freshmen, Sophomore, Junior, or Senior" r...2007-08-25 16:00:33 · 243 阅读 · 0 评论 -
activescaffold插件的基本使用(爆爽的东东)
http://www.activescaffold.com/三步曲1、Install the latest version of the plugin:ruby 代码 ./script/plugin install http://activescaffold.googlecode.com/svn/tags/active_scaffold 2、Add this to ...2007-08-13 10:29:22 · 181 阅读 · 0 评论 -
rails中使用tzinfo-timezone实现各时区时间转换
结合http://marklunds.com/articles/one/311和手册,完整的一个实现各时区时间转换的一个例子:首先保证服务器安装tzinfo插件 gem install tzinfo1、配置环境ruby 代码 ActiveRecord::Base.default_timezone = :utc 2、相应的类中ruby 代码 require 't...2007-08-11 14:48:01 · 546 阅读 · 0 评论 -
dhtml日历插件和show flash messages on cached pages
Show flash messages on cached pagesruby 代码ruby script/plugin install svn://rubyforge.org/var/svn/pivotalrb/cacheable_flash/trunk 时间日历插件http://dry.4thebusiness.com/info/dhtml_calendarruby 代码ruby scr...2007-08-11 14:47:25 · 171 阅读 · 0 评论 -
ruby中rmgaick给图片加版权信息和水印(中文水印)
根据imagemagick和一些网站的资料,总结了常用的加水印(特别是中文)的代码。require 'rubygems'require 'RMagick'#在图片中嵌入中文文字ruby 代码 def t1 img=Magick::Image.read('path\read_image1.jpg').first #图片路径,用相对路径即...2007-07-30 19:30:26 · 415 阅读 · 0 评论 -
ror中文截取乱码解决
puts "在要城在".scan(/./)[0, 6].join('')注意,用utf-8编码,一个汉字三个字节2007-07-12 16:17:20 · 97 阅读 · 0 评论