Rails基础

03 Apr 2013, by

常用rails命令例子

控制台技巧(rails c)

gemfile中版本选择

整理复杂的migrate文件

时间设置

在application.rb中添加以下两条配置:   
config.time_zone = 'Beijing'   
config.active_record.default_timezone = :local   
如果不想在页面中显示本地时区及时差的话:   
created_at.localtime(:db).to_s

常见优化

关于判定布尔值(blank?, empty?, nil?, any?)

>> " ".blank?    # =>   true
>> " ".empty?     # =>   false
>> "foo".nil?
=> false
>> "".nil?
=> false
>> nil.nil?
=> true
>> a = ["free ", "qq "]
>> a.any?
 # =>   true

>> a = []
>> a.any?
 # =>   false

>> a = [ ]
>> a.any?
 # =>   false

>> a = [" "]
>> a.any? # =>   true

常见问题