I thought I had this solved in a previous post but I'm still struggling with it. In my Rails app I'm trying to give user the ability to message each other within the app (Not through email). I'm using rails 3.2.8 and ruby 1.9.3p194
Message belongs_to :user
User has_many :messages
Here is my method for sending messages in my Message Model
def self.send_message(from, recipient)
recipient do |recipient|
msg = self.clone
msg.sent = false
msg.user_id = recipient
msg.save
end
self.update_attributes :user_id => from.id, :sent => true
end
I'm trying to test this in the rails console by doing: Message.send_message(u2,u)
where u2 = User.find(1) & u = User.find(2)
I keep getting the error NoMethodError: undefined method `recipient' for #
What am I doing wrong? How can I properly send a user a message from another user.
I'm open to any strategy if someone has a better way.