-3

添加此代码

def send_messages
  return if recipient_list.blank?

  recipient_list.each do |recipient|
  recipient = User.find(recipient)
  messages.build(user_id: recipient.id, conversation_id: self.id)
end

对我的模型

class Conversation < ActiveRecord::Base
  attr_accessible :recipient_list
  after_create :send_messages

  has_many :messages
end

导致对我的模型的任何引用抛出

syntax error, unexpected $end, expecting keyword_end

从模型...没有它我的模型工作得很好。这段代码有问题吗?

4

1 回答 1

4

您错过了关闭 do 块的结束:

def send_messages
  return if recipient_list.blank?

  recipient_list.each do |recipient|
    recipient = User.find(recipient)
    messages.build(user_id: recipient.id, conversation_id: self.id)
  end
end
于 2012-08-26T09:22:02.857 回答