生成指定版本的Rails项目 - 2019-05-05 17:32:23

本地 Rails 默认5.0.2 版本 $ gem list --local rails (5.0.2, 5.0.0.1, 5.0.0, 4.2.8) 使用 _version_ 生成指定version的项目 rails _version_ new application_name 例如生成 4.2.8 版本 rails _4.2.8_ new todolists

ActiveRecord’s Queries tricks 小记 - 2019-05-04 16:32:44

原文 https://medium.com/rubyinside/active-records-queries-tricks-2546181a98dd 关联表join时使用条件 # User model scope :activated, ->{ joins(:profile).where(profiles: { activated: true }) } 更好的做法 # Profile model scope :activated, ->{ where(activated: true) } # User model scope :activated, ->{ joins(:profile).merge(Profile.activated) } 关于 merge https://apidock.com/rails/ActiveRecord/SpawnMethods/merge https://api.rubyonrails.org/classes/ActiveRecord/SpawnMethods.html 嵌套join的差异 User has_one Profile Profile has_many Skills User.joins(:profiles).merge(Profile.joins(:skills)) => SELECT users.* FROM users INNER JOIN profiles ON profiles.user_id = users.id LEFT OUTER JOIN skills ON skills.profile_id = profiles.id # So you'd rather use: User.