了解这个spell的基础是,你要知道 alias_method :的用法: alias_method :new_name, :old_name 这个东东非常常见,遍及RAILS代码的每个角落。起源是: 1. 假设我们希望为某个方法加上新功能:  可以用 alias_method. ActionController::TestCase.class_eval do # sa...
Rbenv+passenger:nosuchfiletoload:rubygemspath_support
refer to: http://stackoverflow.com/a/15777738/445908 In my case, I also met this problem: ( My environment: Centos 5.8, rbenv 1.9.3p327, passenger 3.0.19, nginx( compiled and installed by passen...
Rails的精髓之:activesupport(studyingacitve Support)
用了Rails 4年多了。不过还没认真看过ActiveSupport. 只是发现很多优雅的方法都是出自于其中: blank?  in? revert_merge try 所以,今天看了一下。发现最重要的一点是:如何引用 ActiveSupport: require 'active_support'  # doesn't work require 'active_sup...
Railsmacro如何定义?wheretodefinemacrosinrails?
http://stackoverflow.com/questions/926489/rails-macro-style-functions 如何定义rails macro? 上面的文章描述的很全面了。 对于controller使用的,就定义在application controller中。对于model会使用的,就reopen activerecord::base For model...
一个视图层的gem:apotomo(rubygemapotomoforrails.)
好吧,我失败了。。。 没有成功的跑起来,虽然经过查看源代码等等修改,也还是一直有失败消息。我怀疑这个GEM 不兼容 3.2.11 ,或者作者已经停止维护了(上一次提交代码是2个月前,再一次是8个月前,还有20+ issue没有 解决, 好多pull request 没有处理) (OK, I admit that I failed to manage this to work. I d...
Rails中的rubygem:cells(cellsrubygem)
这几天在弄Rails engine gem, 然后从 regular rubygem -> enginex -> rails plugin ->  Apotomo  -> 'cells'.    ( these days I am dealing with how to setup 'rails engine gem', the...
如何打印可读性强的json:(pretty Readablejsoninruby)
http://stackoverflow.com/questions/86653/how-can-i-pretty-format-my-json-output-in-ruby-on-rails 43 json = Cms::Utils.object(videoid) 44 logger.info "== json for url( #{url}) : #{JSON.p...
建立railsenginegem(howtowritearailsenginegem)
注意:这个文章只针对Rails3.0.x 对于 后面的版本  , 请看 $ rails plugin new (Enginex is only available for Rails 3.0. *For Rails 3.1 onwards, Enginex was ported to Rails as `rails plugin new` by Piotr Sarnacki.* ...
Forchineservmusers:ruby.taobao.org
国内的同学门,安装 RVM之后记得走淘宝哦~    安装各种rubygem也可以~~~ 详情见:  ruby.taobao.org 复制过来的内容: $ gem sources --remove https://rubygems.org/$ gem sources -a http://ruby.taobao.org/$ gem sources -l*** CUR...
如何查看某个action的restful类型?(howtodeterminetherestfultypeofanactioninrails?)
今天为了这个问题想了半小时。呃。。。又是看RAILS源代码又是查文档啥的。 后来才发现,有个灰常简单的方法:  ( today I spent half an hour on this question, checking both the source code  and the documentation.  at last, I found this ve...
在rails中,删除某个hash中的多个key(deletemultiplekeysfromahashinrails)
参考: http://stackoverflow.com/questions/1560572/ruby-delete-multiple-hash-keys sg552@youku:/sg552/workspace/postman$ bundle exec rails c Loading development environment (Rails 3.2.9) >> ap...
Rails中使用cache(最简单的)(cachinginrailsfordifferentparameters)
http://stackoverflow.com/questions/1988658/rails-action-caching-with-querystring-parameters 1. in production.rb, : config.action_controller.perform_caching = true 2. in your controller : (will...
Rails:慎用f.check_box,推荐使用check_box_tag(prefertousecheck_box_tagorhash,butnotf.checkboxinrails)
TODO: 翻译成汉语  Returns a checkbox tag tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object). This o...
在rails3中,保存任意结构的对象到数据库(saveschema Lessobjecttorailsdb'sstringcolumn)
Saving arrays, hashes, and other non-mappable objects in text columns AR 可以保存任意对象到 TEXT 列。如下:   ( Active Record can serialize any object in text columns using YAML. To do so, you must specify...
Rails中使用uploadify插件(usinguploadifyinrails3)
这个插件非常好用。 可以看作是 SWFupload的后续 (SWFUPLOAD已经停止开发好久好久了) 使用步骤也是一般吧,不是一下就可以搞定(我昨天花了大半天时间才做了个满意的封装,虽然我很讨厌封装),但是也不是特别麻烦。可以说解藕做的不错~   实现它的缘由1. 由于我们的图片都保存在一个远程服务器上,所以我们不需要在本地永久保存上传的数据。 对应的数据库中的列也只是一个Str...
Cancan的aliasaction与核心方法can(aliasactionofcancananditscoremethod:can)
( 从 CanCan::Ability 这个RDOC中拿过来的)( grabbed from its rdoc) 1. 核心方法 can 可以定义 可用的ability. 参数1是 action, 参数2 是对象名 (Defines which abilities are allowed using two arguments. The first one is the ac...
测试文件上传(testfileuploadinrails)
非常简单。 You can use fixture_file_upload method to test file uploading: Put your test file in "{Rails.root}/spec/fixtures/files" directory before :each do @file = fixture_file_upload('files/test_...
使用bundler开发rubygem(developingarubygemusingbundler)
For English original post, please visit:   https://github.com/radar/guides/blob/master/gem-development.md Bundler is a tool created by Carl Lerche, Yehuda Katz, André Arko and various superb ...
建立一个rubygem(howtocreatearubygem)
参考:  http://guides.rubygems.org/make-your-own-gem 1. 假设你的gem名字是 "hola", 就要先建立这样的目录结构。(记得 lib下要有个跟项目同名的rb文件哦) % tree . ├── hola.gemspec └── lib └── hola.rb 2. 编辑 lib/hola.rb 这个文件,让它看起来如...
Ruby操作zookeeper的比较(zookeeperrubyclientscomparison)
为了寻找一个比较合适的RUBY ZOOKEEPER客户端,搜索了一下。( I am involving a project that uses zookeeper as a component and I am looking for a suitable ruby client for zookeeper. and I googled around with the results bel...