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.

a few interesting rails plugin

08月 6, 2008 · Posted in Promgramming · 2 Comments 

最近开发中遇到一些有趣的rails pulgin,好像国内连介绍都没有,所以打算写写。

Rails Widgets

http://www.seesaw.it/en/toolbox/widgets/

一个DSLful的Page widgets plugin,让你简单地在页面上添加各种widgets,如tab,nav等,这些似乎是现在页面上不可或缺的页面元素。这个框架旨在减少手工维护这些widgets的代价,手工维护的话,so buggy!

具体看其演示文档可以看到它是干嘛的。


Bj

http://codeforpeople.rubyforge.org/svn/bj

一个让Rails参与管理Server上后台进程(background job)的plugin。这样有什么好处呢?如果你前台Rails app是使用了后台的某些服务的,那这个插件就非常有用了。

不过这个plugin非常少资料,只能从它的README中获得比较多的信息。

……

a bug in attachment_fu

07月 28, 2008 · Posted in Promgramming · 1 Comment 

attachment_fu ,一个Rails插件,帮助你轻松处理文件上传。

最近使用它时遇到一个bug,其中用到了它的s3存储管理,发现如果没有指定缩略的参数时更新会出错,看了一下原来是默认参数nil出的错,当在File#join路径时,会调用每个参数的to_s方法,这样nil.to_s当然就出错了。或许,大家使用s3存储,并使用了attachment_fu时都存的是缩略图,所以没有遇到这个bug吧。这个错误只出现在update时,报的错是type error。

  1. # line 196
  2. def full_filename(thumbnail = nil)
  3.   File.join(base_path, thumbnail_name_for(thumbnail))
  4. end

我已经fix了这个bug,并ci到attachment_fu在github的repo。

fix s3 no thumbnail update error bug

mark一篇文章,关于如何在github上ci path:
http://railsontherun.com/2008/3/3/how-to-use-github-and-submit-a-patch

这是我第一次向开源项目提交代码^_^

下一页 »