Ruby on rails 使用多个模型的Mailboxer Gem
我有两个模型,用户和员工需要相互交互。这是一个基于示例应用程序()的控制器。我需要它对这两种型号都起作用,但为def(如邮箱等)添加if/else语句以确定员工或用户是否登录会显示“堆栈级别太深”错误。我是rails新手,在多次谷歌搜索/SO后,我无法理解自己的错误。消息传递应该在这两个模型之间,并且发起者应该是用户。(更新:我找到一个SO帖子) 非常感谢Ruby on rails 使用多个模型的Mailboxer Gem,ruby-on-rails,ruby,ruby-on-rails-4,model,mailboxer,Ruby On Rails,Ruby,Ruby On Rails 4,Model,Mailboxer,我有两个模型,用户和员工需要相互交互。这是一个基于示例应用程序()的控制器。我需要它对这两种型号都起作用,但为def(如邮箱等)添加if/else语句以确定员工或用户是否登录会显示“堆栈级别太深”错误。我是rails新手,在多次谷歌搜索/SO后,我无法理解自己的错误。消息传递应该在这两个模型之间,并且发起者应该是用户。(更新:我找到一个SO帖子) 非常感谢 class ConversationsController < ApplicationController before_filt
class ConversationsController < ApplicationController
before_filter :authenticate_employee! or authenticate_user!
helper_method :mailbox, :conversation
def create
recipient_emails = conversation_params(:recipients).split(',')
recipients = User.where(email: recipient_emails).all
if(user_signed_in?)
conversation = current_user.send_message(recipients, *conversation_params(:body, :subject)).conversation
else
conversation = current_employee.send_message(recipients, *conversation_params(:body, :subject)).conversation
end
redirect_to conversation_path(conversation)
end
def reply
current_user.reply_to_conversation(conversation, *message_params(:body, :subject))
redirect_to conversation_path(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
if(user_signed_in?)
@mailbox ||= current_user.mailbox
else
@mailbox ||= current_employee.mailbox
end
redirect_to conversation_path(conversation)
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`
类会话控制器
由于无限循环/递归/重定向,“堆栈级别太深”错误通常会出现。查看上面的代码,我没有发现任何明显的罪魁祸首,但使用pry进行调试可能会帮助您找到它。我只添加了一些if/else语句,而控制器代码的其余部分可以正常工作(有问题的链接)。将使用撬杆和立柱进行检查!