aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_record_querying.textile
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2012-01-24 23:53:56 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2012-01-24 23:53:56 +0530
commitd26a166cfbd5c7f67277256aa74e6cc1df7feb77 (patch)
tree477c68edd1db5508333acf9f5eeb68b79bc0c629 /railties/guides/source/active_record_querying.textile
parent82e2f19aac68e1ee05484a2247d2d7771fe3f66f (diff)
downloadrails-d26a166cfbd5c7f67277256aa74e6cc1df7feb77.tar.gz
rails-d26a166cfbd5c7f67277256aa74e6cc1df7feb77.tar.bz2
rails-d26a166cfbd5c7f67277256aa74e6cc1df7feb77.zip
fix some examples - method names can't start with a number
Diffstat (limited to 'railties/guides/source/active_record_querying.textile')
-rw-r--r--railties/guides/source/active_record_querying.textile10
1 files changed, 5 insertions, 5 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 5970a45839..84687e2e4f 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -965,7 +965,7 @@ If you're working with dates or times within scopes, due to how they are evaluat
<ruby>
class Post < ActiveRecord::Base
- scope :last_week, lambda { where("created_at < ?", Time.zone.now ) }
+ scope :created_before_now, lambda { where("created_at < ?", Time.zone.now ) }
end
</ruby>
@@ -977,21 +977,21 @@ When a +lambda+ is used for a +scope+, it can take arguments:
<ruby>
class Post < ActiveRecord::Base
- scope :1_week_before, lambda { |time| where("created_at < ?", time) }
+ scope :created_before, lambda { |time| where("created_at < ?", time) }
end
</ruby>
This may then be called using this:
<ruby>
-Post.1_week_before(Time.zone.now)
+Post.created_before(Time.zone.now)
</ruby>
However, this is just duplicating the functionality that would be provided to you by a class method.
<ruby>
class Post < ActiveRecord::Base
- def self.1_week_before(time)
+ def self.created_before(time)
where("created_at < ?", time)
end
end
@@ -1000,7 +1000,7 @@ end
Using a class method is the preferred way to accept arguments for scopes. These methods will still be accessible on the association objects:
<ruby>
-category.posts.1_week_before(time)
+category.posts.created_before(time)
</ruby>
h4. Working with scopes