Ruby on Rails Wednesday, September 24, 2014

Try using scope.


===================
Alexandre Mondaini Calvão

"Nossa recompensa se encontra no esforço e não no resultado. Um esforço total é uma vitória completa." [Ghandi]

2014-09-24 12:52 GMT-03:00 Jason Fleetwood-Boldt <tech@datatravels.com>:


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. 

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)? 

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.

-Jason



On Sep 24, 2014, at 10:13 AM, Jan Yo <lists@ruby-forum.com> wrote:

Rspec forum isn't working

Rspec is having trouble recognizing where method.

Here's the rspec output:

 NoMethodError:
      undefined method `where' for #<Article:0x000000066ceb38>
    #
/apps/rvm/gems/ruby-2.0.0-p481/gems/activemodel-4.0.10/lib/active_model/attribute_methods.rb:439:in
`method_missing'
    #
/apps/rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.10/lib/active_record/attribute_methods.rb:168:in
`method_missing'
    #
/apps/rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.10/lib/active_record/querying.rb:9:in
`where'


The spec calls index which then calls a public method that uses the
following method:

class X < ActiveRecord::Base
 def self.low_level
   where(:level=> 1)
 end
end

Any ideas what could be the problem?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/A1755A1E-C112-4148-9B31-C2FC70BEB82C%40datatravels.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CA%2BaBw4RgP_3JJ7ow-CdaYw3eB0wCOuKg-G1c3NWhMP9k1ByOnw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment