database.yml & capistrano2

10月 4, 2008 · Posted in Promgramming · 4 Comments 

实验室的服务器配置好了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

09月 11, 2008 · Posted in Promgramming · 1 Comment 

最近在其中一个项目中需要对Rails app进行i18n,时不时会查查Rails源码,昨日在insoshi的mailist中看到了这个link:

http://rails-i18n.org/wiki

建议对此有兴趣的人去看看,基本上把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

09月 11, 2008 · Posted in Agile, Promgramming · Comment 

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:

  1. # app/controllers/spelling_controller.rb
  2. class SpellingController << ApplicationController
  3.   def check
  4.     render :update do |page|
  5.       page.replace_html 'check-result', SpellingChecker.check_spell(params[:text])
  6.     end
  7.   end
  8. end

Add a SpellingChecker Class to Lib

  1. # lib/spelling_checker.rb
  2. class SpellingChecker
  3.  
  4.   def self.check_spell text
  5.     speller = Aspell.new("en_US")
  6.     speller.suggestion_mode = Aspell::NORMAL
  7.     wrongs = []
  8.     text.gsub(/[\w\']+/) do |word|
  9.       wrongs << word unless speller.check(word)
  10.     end
  11.     wrongs.uniq.each do |wrong|
  12.       text.sub!(wrong, "<span class='wrong'>#{wrong}</span>")
  13.     end
  14.     return text
  15.   end
  16.  
  17. end

in the view:

  1. <label for="description">Description: </label>
  2.   <div id="check-desc" style="display:none;">
  3.     <%=link_to_function 'Resume editing', "ttoggleChecking()" %>
  4.     <br />
  5.     <div id="check-result">Checking...</div>
  6.   </div>
  7.   <div id="edit-desc">
  8.     <%=link_to_function 'Check spelling', "new Ajax.Updater({ success:toggleChecking()},
  9.                                                             '/spelling/check',
  10.                                                             {method:'get', parameters:{text:$F('ticket_description')}});" %>
  11.     <br />
  12.     <%= f.text_area :description, :cols => 84, :rows => 10 %>
  13.   </div>
  14.   <script type='text/javascript'>
  15.     function toggleChecking() {
  16.       $('edit-desc', 'check-desc').invoke('toggle');
  17.     }
  18.   </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

08月 26, 2008 · Posted in Promgramming · Comment 

Ruby1.9的库,NerverBlock,非阻塞IO。

http://www.espace.com.eg/neverblock

看看它的官网上的benchmarks就知道真的是解放。

a rspec cheetsheet

08月 22, 2008 · Posted in Promgramming · Comments Off 

from:http://coldfire.org.ua/blog/?p=26

a rspec cheetsheet, cool!

rspec cheetsheet thumbail

download: http://coldfire.org.ua/blog/wp-content/uploads/2007/04/rspec_cheetsheet.png

下一页 »