views:

24

answers:

1

I have a notification list that the user can select different show options for different kinds of notifications along with how many results are returned. I'm keeping them in the user model because I want the custom sort to stay with the user between sessions. Here is the association in my user model:

has_many :notifications,
       :class_name => "Notification",
       :foreign_key => "user_id",
       :conditions => ["won = ? and lost = ? and paid = ?", self.prefs_won, self.prefs_lost, self.prefs_paid],
       :limit => self.prefs_results.to_s

But when I use the above code, Rails throws me an "unknown method" error for self.prefs_won. It is definitely a field in my database and set as a boolean value, but Rails can't find it... what's the problem?

EDIT:

Here's the migration:

  t.boolean   :prefs_won, :default => true
  t.boolean   :prefs_lost, :default => true
  t.boolean   :prefs_paid, :default => true
  t.integer   :prefs_results, :default => 10
+1  A: 

ActiveRecord accessors for boolean attributes have a question mark at the end of the attribute name. Try self.prefs_won? instead.

John Topley
Still getting an error: "undefined method `prefs_won?' for #<Class:0x57eb9c8>".
Kevin