rewrite in ruby on rails