Ruby on Rails Wednesday, September 24, 2014


I think what apotema@gmail.com pointed out is most poignant, you can accomplish what you are trying to accomplish with this (ruby 2 syntax)

scope :low_level, -> { where(:level => 1) }


The you reference this scope as Article.low_level

as you get your hands dirty with AR scopes, read & understand what "lazy evaluation" is in the query lifecycle.







On Sep 24, 2014, at 5:18 PM, Jan Yo <lists@ruby-forum.com> wrote:

Jason Fb wrote in post #1158388:
Jan,

That is pretty strange-- but it looks like you're doing something
non-standard and you've gotten yourself into a pickle.

I notice that the error message says there's no method 'where' on an
instance of an Article. Normally you call where on the class itself.

Good point

First of all, why is your class named "X" in your example (did you do
that just to share you code? It's a little confusing)?

I did that just to share code

Secondly, can you show us the calling code please?

Finally, put a debugging statement inside of self.low_level and then
type "self" to understand the context (scope) of how it is called -- if
"self" inside the method is actually your Article class or (somehow) an
instance of an Article.

Good idea

-Jason


No comments:

Post a Comment