database.yml & capistrano2
实验室的服务器配置好了apache2+passenger2的环境,就很开心试了capistrano2远程部署。
要使用capistrano2来作远程的deploy当然要把服务器配置好ssh,web server等,我的做法是创建一个deploy的user专门来干这档事,并把deploy加入到www-data组以便在服务器的空间有权限写入。不过在试用过程中发现如果是使用scm的话capistrano2是不管你database.yml(因为不可能把production server的db账户信息纳入版本控制),想想可能放在share目录下应该就可以解决(share目录专门放些不变的东西,如log,如一些如用户资源等静态数据),但具体怎样还是看看别人怎么做的,搜索一下看到这个POST。这位老兄加了个两个钩子,在setup和update_code时把事先准备的模板放到share目录中。但其实还有些问题,数据库的user并不一定就是server的user,最好还是在config/deploy.rb加上两个字段如db_user和db_passwd来设数据库。
看了下Capistrano2的文档,发现真是个好东东,简单又方便。
rails i18n feature
最近在其中一个项目中需要对Rails app进行i18n,时不时会查查Rails源码,昨日在insoshi的mailist中看到了这个link:
建议对此有兴趣的人去看看,基本上把i18n都讲得比较清楚。其中还有个demo:
http://github.com/clemens/i18n_demo_app/tree/master
我clone下来看看后顺手就也加上了zh_CN的locale configure,我先fork了一个分支,花了一个钟,完工pull,不知什么时候才会被merge。大家如果想要了解Rails22的i18n可以看看我汉化过的Demo,enjoy:
http://github.com/maninred/i18n_demo_app
Rails越来越多功能,但也越来越臃肿了。还可以看到Ruby也有很多i18n资源。
check spelling on rails
A few days ago I need to do spell checking for a rails project, but can’t find a ready-to-use plugin, so I implemented one.
I use the Aspell Lib to do the checking work, and ajax for editing.
First you need to install the Aspell and at lease one dictionary.
Mac:
sudo port install aspell aspell-dict-en
Ubuntu:
sudo apt-get install aspell libaspell-dev aspell-en
Arch:
sudo pacman -S aspell aspell-en
And install the Aspell Ruby binding: raspell
sudo gem install raspell
Add a controller:
- # app/controllers/spelling_controller.rb
- class SpellingController << ApplicationController
- def check
- render :update do |page|
- page.replace_html 'check-result', SpellingChecker.check_spell(params[:text])
- end
- end
- end
Add a SpellingChecker Class to Lib
- # lib/spelling_checker.rb
- class SpellingChecker
- def self.check_spell text
- speller = Aspell.new("en_US")
- speller.suggestion_mode = Aspell::NORMAL
- wrongs = []
- text.gsub(/[\w\']+/) do |word|
- wrongs << word unless speller.check(word)
- end
- wrongs.uniq.each do |wrong|
- text.sub!(wrong, "<span class='wrong'>#{wrong}</span>")
- end
- return text
- end
- end
in the view:
- <label for="description">Description: </label>
- <div id="check-desc" style="display:none;">
- <%=link_to_function 'Resume editing', "ttoggleChecking()" %>
- <br />
- <div id="check-result">Checking...</div>
- </div>
- <div id="edit-desc">
- <%=link_to_function 'Check spelling', "new Ajax.Updater({ success:toggleChecking()},
- '/spelling/check',
- {method:'get', parameters:{text:$F('ticket_description')}});" %>
- <br />
- <%= f.text_area :description, :cols => 84, :rows => 10 %>
- </div>
- <script type='text/javascript'>
- function toggleChecking() {
- $('edit-desc', 'check-desc').invoke('toggle');
- }
- </script>
This is what it looks like:
That is it, quite sample, isn’t it? I would like to make a plugin for it, but no much time recently.
Thank yawl for pointing out my grammar misstake.
Ruby也要解放IO
Ruby1.9的库,NerverBlock,非阻塞IO。
http://www.espace.com.eg/neverblock
看看它的官网上的benchmarks就知道真的是解放。
a rspec cheetsheet
from:http://coldfire.org.ua/blog/?p=26
a rspec cheetsheet, cool!
![]()
download: http://coldfire.org.ua/blog/wp-content/uploads/2007/04/rspec_cheetsheet.png














