views:

75

answers:

3

I'm using ruby on rails 2.3.8 and when I write the syntax shown below I get the "stack level too deep" error message.

The model is called Announcement and the line of the error looks like this:

Tag.find(category_id).announcements.published

Where published is

named_scope :published, :conditions => "announcements.state = 'published'"

I use this named scope in many other places and it works fine.

What am I doing wrong? (the relationship between Tag and Announcement model is ok because if I remove the ".published" method from that line it works just fine).

EDIT:

The model's relationships are:

class Tagging < ActiveRecord::Base
  belongs_to :announcement
  belongs_to :tag
end

class Tag < ActiveRecord::Base
  has_many :taggings
  has_many :announcements, :through => :taggings
end

class Announcement < ActiveRecord::Base
  has_many :taggings
  has_many :tags, :through => :taggings
A: 

hi Brian Roisentul

Stack Level too deep normally comes when rails is recursively accessing the same method/function.

try to change your condition and check again, Coz I think there can be conflicts 'published' word

Good way of debug would be start with

Tag.find(category_id)

then if there is no erros

Tag.find(category_id).announcements

and still you are ok then

Tag.find(category_id).announcements.published

by that way you will find where exactly the problem is

cheers

sameera

sameera207
I debugged all the steps and the problem is when I add ".published" to that line. Is it possible my model's relationships are wrong? I'll edit my post with them.
Brian Roisentul
A: 

I have no idea if this is the problem, but could you please try using the named_scope like the following and tell us if this worked?

named_scope :published, :conditions => "state = 'published'"
j.
A: 

Where did you write the named scope ?

you should write it in the Announcement model and you have to modify it a little bit

named_scope :published, :conditions => {:state => "published"}

I think you have written the published named_scope in a different model, please correct me if I am wrong.

Vamsi
I don't have any other named scope called like that.
Brian Roisentul