Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3271638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:44:51+00:00 2026-05-17T18:44:51+00:00

As part of learning ruby/rails, I’m trying to implement http://github.com/professionalnerd/simple-private-messages into my application from

  • 0

As part of learning ruby/rails, I’m trying to implement http://github.com/professionalnerd/simple-private-messages into my application from scratch, instead of just installing the plugin. (I know, causing myself trouble but it’s a good learning experience.)

I created the model, and the associations seem ok and I can create new messages fine and they show up in the recipients mailbox. But if I click to view one message (calls the show method in the message controller) it trips up on looking for a method called ‘read’ eg.

undefined method `read' for #<Class:0xb6f9ef78>

Where should I put the ‘read’ method. In private_messages_extensions.rb (the plugin source) it has:

  module ClassMethods
    # Ensures the passed user is either the sender or the recipient then returns the message.
    # If the reader is the recipient and the message has yet not been read, it marks the read_at timestamp.
    def read(id, reader)
      message = find(id, :conditions => ["sender_id = ? OR recipient_id = ?", reader, reader])
      if message.read_at.nil? && reader == message.recipient
        message.read_at = Time.now
        message.save!
      end
      message
    end
  end

  module InstanceMethods
    # Returns true or false value based on whether the a message has been read by it's recipient.
    def read?
      self.read_at.nil? ? false : true
    end

What is the relationship between Class methods and Instance methods in relation to inserting directly into my own messages controller & model? I thought I inserted

def read(id, reader)
...
end

into the model, but the read? method in the instance methods section of the plugin code is confusing me and I continue to get the error on viewing a message.

Help appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:44:52+00:00Added an answer on May 17, 2026 at 6:44 pm

    ClassMethods / InstanceMethods is standard Ruby technique that is based on this code:

    def self.included(base)
      base.extend ClassMethods
      base.include InstanceMethods
    end 
    

    which you will (roughly) find in the original code. By the way there is ActiveSupport::Concern that can simplify the code above (take a look into the documentation for more info)

    So whenever the module is included in class then all methods in ClassMethods module will became class methods of the target class and all methods in InstanceMethods will become instance methods of target class.

    So your read method is class method, which has to be called as:

    m = MyModel.new
    m.read?          # => ok, it is an instance method
    MyModel.read     # => ok, it is a class method
    m.read           # => oops, WRONG! FAILURE! 
                     # You are calling class method through object
    

    Meta-programming rules!

    If you rewrite the code without meta thing, you should write it as:

    class MyModel
      def self.read
      end
    
      def read?
      end
    
    end    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a very simple application (part of my learning program),
As part of learning jQuery, I decided to do a simple tic-tac-toe game in
I just uploaded my first ASP.NET (as part of my learning of vb.net) and
I'm learning DirectX as part of a hobby project. I've been looking for some
I am learning to use LabVIEW as part of my honours project, and was
As part of learning android, I am following the NotePad tutorial One thing I
As part of my learning, i am developing a google maps V3 application, to
query level: beginner As part of a learning exercise I have written code that
Part of my everyday work is maintaining and extending legacy VB6 applications. A common
Part of a new product I have been assigned to work on involves server-side

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.