对于我的自定义收件箱邮件系统,我正在设置已发送邮件文件夹。我得到wrong number of arguments (1 for 0)
。该页面的标题是MessagesController #index中的ArgumentError。我似乎无法正确定义方法。任何帮助将不胜感激,因为我尝试了一些东西,但似乎无法让它工作。我确信它是正常的小修复,但我是rails的新手,所以我还不知道所有的方法。
user.rb:
def received_messages
Message.received_by(self)
end
def unread_messages?
unread_message_count > 0 ? true : false
end
def sent_messages
Message.sent_by(self)
end
message.rb:
class Message < ActiveRecord::Base
attr_accessible :subject, :body, :sender_id, :recipient_id, :read_at,:sender_deleted,:recipient_deleted
validates_presence_of :subject, :message => "Please enter message title"
belongs_to :sender,
:class_name => 'User',
:foreign_key => 'sender_id'
belongs_to :recipient,
:class_name => 'User',
:foreign_key => 'recipient_id'
# marks a message as deleted by either the sender or the recipient, which ever the user that was passed is.
# When both sender and recipient marks it deleted, it is destroyed.
def mark_message_deleted(id,user_id)
self.sender_deleted = true if self.sender_id == user_id
self.recipient_deleted = true if self.recipient_id == user_id
(self.sender_deleted && self.recipient_deleted) ? self.destroy : self.save!
end
# Read message and if it is read by recipient then mark it is read
def readingmessage
self.read_at ||= Time.now
save
end
# Based on if a message has been read by it's recipient returns true or false.
def read?
self.read_at.nil? ? false : true
end
def self.received_by(user)
where(:recipient_id => user.id)
end
def self.not_recipient_deleted
where("recipient_deleted = ?", false)
end
def self.sent_by(user)
user.messages.sent
end
端
messages_controller:
def index
if params[:mailbox] == "sent"
@messages = @user.sent_messages
elsif params[:mailbox] == "inbox"
@messages = @user.received_messages
#elsif params[:mailbox] == "archieved"
# @messages = @user.archived_messages
end
end
inbox.html.erb:
<%= link_to "View Sent Messages", user_messages_path(current_user, :mailbox => :sent)%>
答案 0 :(得分:1)
看起来您对Message.sent_by的定义不正确,请尝试:
# message.rb
def self.sent_by(user)
Message.where(:sender_id => user.id)
end