2008年8月8日 星期五

Rails 2.1 new features


http://www.javaeye.com/news/2320
has_one :through
  1. class Magazine <>
  2. has_many :subscriptions
  3. end
  4. class Subscription <>
  5. belongs_to :magazine
  6. belongs_to :user
  7. end
  8. class User <>
  9. has_many :subscriptions
  10. has_one :magazine, :through => : subscriptions, :conditions => ['subscriptions.active = ?', true]
  11. end



http://www.javaeye.com/news/2334
Gem: Dependencies
  1. Rails::Initializer.run do |config|
  2. # Require the latest version of haml
  3. config.gem "haml"
  4. # Require a specific version of chronic
  5. config.gem "chronic", :version => '0.2.3'
  6. # Require a gem from a non-standard repo
  7. config.gem "hpricot", :source => "http://code.whytheluckystiff.net"
  8. # Require a gem that needs to require a file different than the gem's name
  9. # I.e. if you normally load the gem with require 'aws/s3' instead of
  10. # require 'aws-s3' then you would need to specify the :lib option
  11. config.gem "aws-s3", :lib => "aws/s3"
  12. end


http://www.javaeye.com/news/2349
Dirty Objects
  1. article = Article.find(:first)
  2. article.changed? #=> false
  3. # Track changes to individual attributes with
  4. # attr_name_changed? accessor
  5. article.title #=> "Title"
  6. article.title = "New Title"
  7. article.title_changed? #=> true
  8. # Access previous value with attr_name_was accessor
  9. article.title_was #=> "Title"
  10. # See both previous and current value with attr_name_change accessor
  11. article.title_change #=> ["Title", "New Title"]
  12. # Get a list of changed attributes
  13. article.changed #=> ['title']
  14. # Get the hash of changed attributes and their previous and current values
  15. article.changes #=> { 'title' => ["Title", "New Title"] }
http://www.javaeye.com/news/2367
Partial updates
  1. article = Article.find(:first)
  2. article.title #=> "Title"
  3. article.subject #=> "Edge Rails"
  4. # Update one of the attributes
  5. article.title = "New Title"
  6. # And only that updated attribute is persisted to the db
  7. article.save
  8. #=> "UPDATE articles SET title = 'New Title' WHERE id = 1"
ActiveRecord::Base.partial_updates = true

http://www.javaeye.com/news/2377
named_scope

http://www.javaeye.com/news/2392
UTC-based Migration

http://www.javaeye.com/news/2417
http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/
http://wiki.rubyonrails.org/rails/pages/HowtoSetDefaultTimeZone
http://blog.labratz.net/articles/2007/4/11/rails-time-zone-guide-for-beginners



沒有留言: