title: undefined method `id' from self.id
body: <p>I am building a inbox messaging system from scratch and when I add self.id to the condition in the model I get a undefined method `id' error on all pages with a title of NoMethodError in MessagesController. I have tried a few workarounds though I can't get a grip on it.</p>
  
  <p>messages_controller:</p>
  
  <pre><code>class MessagesController &lt; ApplicationController
  
    before_filter :set_user
  
    def index
      if params[:mailbox] == "sent"
        @messages = @user.sent_messages
      elsif params[:mailbox] == "inbox"
        @messages = @user.received_messages
      #elsif params[:mailbox] == "archieved"
       # @messages = @user.archived_messages
      end
    end
  
    def new
      @message = Message.new
      if params[:reply_to]
        @reply_to = User.find_by_user_id(params[:reply_to])
        unless @reply_to.nil?
          @message.recepient_id = @reply_to.user_id
        end
      end
    end
  
    def create
      @message = Message.new(params[:message])
      @message.sender_id = params[:user_id]
      if @message.save
        flash[:notice] = "Message has been sent"
        redirect_to user_messages_path(current_user, :mailbox=&gt;:inbox)
      else
        render :action =&gt; :new
      end
    end
  
    def show
      @message = Message.readingmessage(params[:id],@user_id)
    end
  
    def delete_multiple
        if params[:delete]
          params[:delete].each { |id|
            @message = Message.find(id)
            @message.mark_message_deleted(@message.id,@user_id) unless @message.nil?
          }
          flash[:notice] = "Messages deleted"
        end
        redirect_to user_messages_path(@user, @messages)
    end
  
    private
      def set_user
        @user = current_user
      end
  end
  </code></pre>
  
  <p>user.rb:</p>
  
  <pre><code>:conditions =&gt; ["messages.recipient_deleted = ? AND messages.recipient_id = ?",false,self.id]
  ..
   ..
  
   def unread_messages?
     unread_message_count &gt; 0 ? true : false
   end
  
   # Returns the number of unread messages for this user
   def unread_message_count
     eval 'messages.count(:conditions =&gt; ["recepient_id = ? AND read_at IS NULL", self.user_id])'
   end
  </code></pre>