添加此代码会破坏我的模型

时间:2012-08-26 09:19:12

标签: ruby-on-rails model syntax-error

添加此代码

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

从模型中......没有它,我的模型完美无缺。这段代码有问题吗?

1 个答案:

答案 0 :(得分: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