我正在开发我的第一个RoR网站,然后我完成了安装simple_private_messages的步骤。这是它看起来的样子吗? http://i.imgur.com/HTootKv.jpg
点击“撰写”时收到此错误消息:
NoMethodError in Messages#new
Showing C:/app/views/messages/new.html.erb where line #5 raised:
undefined method `error_message_on' for #<#<Class:0x516e6d0>:0x516c0f0>
我正确地完成了所有步骤(我相信)。
这是我的route.db
resources :users do
resources :messages do
collection do
post :delete_selected
end
end
end
消息/ new.html.erb
<% form_for @message, :url => user_messages_path(@user) do |f| %>
<p>
To:<br />
<%= f.text_field :to %>
<%= error_message_on @message, :to %>
</p>
<p>
Subject:<br />
<%= f.text_field :subject %>
<%= error_message_on @message, :subject %>
</p>
<p>
Message<br />
<%= f.text_area :body %>
<%= error_message_on @message, :body %>
</p>
<p>
<%= submit_tag "Send" %>
</p>
<% end %>
消息模型
class Message < ActiveRecord::Base
is_private_message
attr_accessor :to
end
消息控制器
class MessagesController < ApplicationController
before_filter :set_user
def index
if params[:mailbox] == "sent"
@messages = @user.sent_messages
else
@messages = @user.received_messages
end
end
def show
@message = Message.read_message(params[:id], current_user)
end
def new
@message = Message.new
if params[:reply_to]
@reply_to = @user.received_messages.find(params[:reply_to])
unless @reply_to.nil?
@message.to = @reply_to.sender.login
@message.subject = "Re: #{@reply_to.subject}"
@message.body = "\n\n*Original message*\n\n #{@reply_to.body}"
end
end
end
def create
@message = Message.new(params[:message])
@message.sender = @user
@message.recipient = User.find_by_login(params[:message][:to])
if @message.save
flash[:notice] = "Message sent"
redirect_to user_messages_path(@user)
else
render :action => :new
end
end
def delete_selected
if request.post?
if params[:delete]
params[:delete].each { |id|
@message = Message.find(:first, :conditions => ["messages.id = ? AND (sender_id = ? OR recipient_id = ?)", id, @user, @user])
@message.mark_deleted(@user) unless @message.nil?
}
flash[:notice] = "Messages deleted"
end
redirect_to :back
end
end
private
def set_user
@user = User.find(params[:user_id])
end
end