rubytips
sendtocaryl
这个作者很懒,什么都没留下…
展开
-
namespace管理
./script generate scaffold admin/userinclude Admin>>User=>Admin::User>>UsersController=>Admin::UsersController>>UsersHelper=>Admin::UsersHelper原创 2008-12-30 17:38:59 · 120 阅读 · 0 评论 -
ruby和rails中 group_by方法区别
irb:[1, 2, 3, 4, 5,6].group_by{|i| i%2}return a Hash rails console:[1, 2, 3, 4, 5,6].group_by{|i| i%2}return a Array 但都可以用以下方法:result.each do |k,v| puts k, v, ''end ...原创 2008-12-30 17:48:32 · 941 阅读 · 0 评论 -
after_find after_initialize回调方法
虽然api没写,但rails支持after_find after_initialize的回调方法完整的callback是: %w{after_find after_initialize before_save after_save before_create after_create before_update after_update before_validation after_val...原创 2008-12-30 21:35:09 · 336 阅读 · 0 评论 -
model的after_save前sanitize html
ActionView::Helpers::SanitizeHelper中有sanitize方法,可以在view 中使用如果想在model中使用,可以include ActionView::Helpers::SanitizeHelper. 但是会覆盖掉ActiveRecord::Base的sanitize方法 还有一个办法:after_save :sanitize_htmlprivate...原创 2008-12-30 22:36:07 · 221 阅读 · 0 评论 -
语法糖(1)
[].each(&:name) -> [].each{|e|e.name} add = lambda{|a,b| a + b}add.call(1,2) # => 3also:add[1,2] # => 3 collection.each {|x| puts x}also:print_me = lambda{|x| puts x} col...原创 2009-01-11 19:26:05 · 102 阅读 · 0 评论