我正在运行Rails 3并且想要一个消息系统。 这里是它的教程:http://www.novawave.net/public/rails_messaging_tutorial.htmlRails 3:被调用的ID为零,这将错误地为4
这是为Rails 2,所以我想实现它的Rails 3
但经过我打造的“/查看/发送/指数/”,并尝试发送消息(甚至没有人看不懂),我得到了一个错误:
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
app/models/message.rb:16:in `prepare_copies'
app/models/message.rb:14:in `each'
app/models/message.rb:14:in `prepare_copies'
app/controllers/sent_controller.rb:19:in `create'
我的“已发送”控制器的样子:
def create
@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
线#19是“如果@ message.s大声“
所以我GOOGLE了,发现@message可能是零,但我不明白为什么。
“查看/发送/新/” 形式是这样的:
<% form_for :message, :url => {:controller => "sent", :action => "create"} do |f| %>
<p>
To:<br />
<select name="message[to][]">
<%= options_from_collection_for_select(User.find(:all), :id, :username, @message.to) %>
</select>
</p>
<p>Subject: <%= f.text_field :subject %></p>
<p>Body:<br /> <%= f.text_area :body %></p>
<p><%= f.submit %></p>
<% end %>
在错误页面的参数是否正确提交:
Parameters:
{"commit"=>"Save Message",
"authenticity_token"=>"GtJEl2DnKHy06e3IepnnZU0u9RWNlO7gDOx/7FyXFBo=",
"utf8"=>"✓",
"message"=>{"body"=>"test",
"to"=>["2"],
"subject"=>"test"}}
我在“routes.rb中改变了一些线路“但我认为这不是重点。 也许有人得到提示?
电贺
是的,的确,这也是我的猜测:ID = 2的用户没有称为收件箱的文件夹。 – nathanvda 2011-04-27 19:07:23
好的非常感谢你!这是收件箱... 创建新用户后,它工作... – Maaaark 2011-04-27 21:40:17