title: Cross scope parameter passing in Rails 3
body: <p>I am trying to query a db that uses a join to find users that require an alert. My query works fine in the model it is written for and it also works through the scope when the parameter being passed is explicit. However when I pass the parameter as a variable it does not work. Here is my code:</p>
  
  <pre><code>class Alert &lt; ActiveRecord::Base
    belongs_to :user
    attr_accessible :first_alert, :second_alert, :third_alert, :user_id
    def self.find_users_to_alert(time)
      where(:third_alert =&gt; time)
    end
    scope :alerter, find_users_to_alert (here is where i want to pass param)
  end
  
  class User &lt; ActiveRecord::Base
    has_many :alerts
    attr_accessor :password
    attr_accessible :name, :email, :password, :password_confirmation
  
    scope :alerts_to_be_sent, joins(:alerts) &amp; Alert.alerter
  end
  </code></pre>
  
  <p>The error I am getting is a NameError undefined local variable or method. But I would have thought passing the value of the variable in the rails console like:</p>
  
  <pre><code>User.alerts_to_be_sent(5)
  </code></pre>
  
  <p>would be ok. Help would be appreciated thanks.</p>