Я использую учебник http://www.novawave.net/public/rails_messaging_tutorial.html для реализации обмена сообщениями в моем проекте ruby on rails.Я использую ruby 1.9.2 и rails 3 и продолжаю получать эту ошибку
NoMethodError in SentController#create
undefined method 'each_line' for ["35"]:Array
Трассировка приложения:
app/models/message.rb:13:in 'prepare_copies'
app/controllers/sent_controller.rb:24:in 'create'
Модель сообщения:
1 class Message < ActiveRecord::Base
2 belongs_to :author, :class_name => "User"
3 has_many :message_copies
4 has_many :recipients, :through => :message_copies
5 before_create :prepare_copies
6
7 attr_accessor :to #array of people to send to
8 attr_accessible :subject, :body, :to
9
10 def prepare_copies
11 return if to.blank?
12
13 to.each_line do |recipient|
14 recipient = User.find(recipient)
15 message_copies.build(:recipient_id => recipient.id, :folder_id => recipient.inbox.id)
16 end
17 end
18 end
Отправленный контроллер:
class SentController < ApplicationController
...
def create
current_user = User.find(session[:user_id])
@message = current_user.sent_messages.build(params[:message])
if @message.save
flash[:notice] = "Message sent."
redirect_to :action => "index"
else
render :action => "new"
end
end
end
Если я редактирую и использую:
to.each do |recipient|
...
end
Я получаю другую ошибку:
RuntimeError in SentController#create
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
Трассировка приложения:
app/models/message.rb:15:in 'block in prepare_copies'
app/models/message.rb:13:in 'each'
app/models/message.rb:13:in 'prepare_copies'
app/controllers/sent_controller.rb:24:in 'create'