Ruby on rails 命名方法错误未定义的方法`参与者';
我有mailboxer gem设置,当我访问/conversations时,我收到一个Ruby on rails 命名方法错误未定义的方法`参与者';,ruby-on-rails,mailboxer,Ruby On Rails,Mailboxer,我有mailboxer gem设置,当我访问/conversations时,我收到一个未定义的方法参与者'`错误指向带有索引的conversations控制器。我在索引操作中添加了一个conversations实例变量,该变量将包含用户的所有收件箱消息 有人能指出我在定义上哪里错了吗 对话控制器: helper_method :mailbox, :conversation def index @conversations ||= current_user.mailbox.in
未定义的方法
参与者'`错误指向带有索引的conversations控制器。我在索引操作中添加了一个conversations实例变量,该变量将包含用户的所有收件箱消息
有人能指出我在定义上哪里错了吗
对话控制器:
helper_method :mailbox, :conversation
def index
@conversations ||= current_user.mailbox.inbox.all
end
def reply
current_user.reply_to_conversation(conversation, *message_params(:body, :subject))
redirect_to conversation
end
def trash_folder
@trash ||= current_user.mailbox.trash.all
end
def create
recipient_emails = conversation_params(:recipients).split(',')
recipients = User.where(email: recipient_emails).all
conversation = current_user.
send_message(recipients, *conversation_params(:body, :subject)).conversation
redirect_to conversation
end
def reply
current_user.reply_to_conversation(conversation, *message_params(:body, :subject))
redirect_to conversation
end
def trash
conversation.move_to_trash(current_user)
redirect_to :conversations
end
def untrash
conversation.untrash(current_user)
redirect_to :conversations
end
private
def mailbox
@mailbox ||= current_user.mailbox
end
def conversation
@conversation ||= mailbox.conversations.find(params[:id])
end
def conversation_params(*keys)
fetch_params(:conversation, *keys)
end
def message_params(*keys)
fetch_params(:message, *keys)
end
def fetch_params(key, *subkeys)
params[key].instance_eval do
case subkeys.size
when 0 then self
when 1 then self[subkeys.first]
else subkeys.map{|k| self[k] }
end
end
end
end
路线:
resources :users do |user|
end
resources :messages do
member do
post :new
end
end
resources :conversations do
member do
post :reply
post :trash
post :untrash
end
collection do
get :trashbin
post :empty_trash
end
end
我终于可以重现你的问题了,我通过运行:
rails g mailboxer:install
及
您可能需要对数据库中现有的
对话
表做些什么。您收到的确切错误消息是什么?完整的错误消息将包括接收者(例如未定义的“foo”方法“bar”中的“foo”
:String
)以及发生错误的文件和行号。错误来自索引,@conversations | |=当前用户.邮箱.收件箱.所有
确切的错误消息是#未定义的方法参与者命名方法RorHello,您是否将作为可发送消息的行为添加到您的用户模型中?另外,您是否手动创建了对话模型?如果你这样做了,这可能就是问题所在。mailboxer安装脚本应该为您处理该配置。如果您已经有一个对话模型(看起来是这样),我会删除该模型,重新运行安装脚本,然后重新运行rake db:migrate。我最终可以重现您遇到的错误,请看答案。当我第一次开始处理邮箱时,我遵循了这一步骤。我只是重复了这个步骤,我收到了同样的错误。我发布的控制器不起作用,但是如果我从github示例恢复到提供的控制器,那么该页面就起作用了。我没有线索了。你能在一个极小的rails应用程序中重现错误并将链接发布到那个repo吗?谢谢你的尝试。我认为错误可能是由于模型造成的。我可能需要正确配置对话模型。
rake db:migrate