首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mailboxer Gem使用多个模型

Mailboxer Gem使用多个模型
EN

Stack Overflow用户
提问于 2014-07-22 01:34:05
回答 1查看 365关注 0票数 0

我有两个模型User和employee,它们需要相互交互。这是一个基于示例应用程序(controller)的控制器。我需要它对两个模型都有效,但是为def添加if/else语句来确定是否有员工或用户登录,会显示“堆栈级别太深”的错误。我是rails的新手,在多次谷歌搜索之后,我不能理解我的错误是什么。消息传递应该在这两个模型之间进行,发起者应该是用户。(更新:我找到了一个Mailboxer Gem--Restrict messaging的帖子)非常感谢!

代码语言:javascript
复制
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`
EN

回答 1

Stack Overflow用户

发布于 2014-07-22 11:56:03

“堆栈级别太深”错误通常是由于无限循环/递归/重定向而出现的。看一下上面的代码,我没有看到任何明显的罪魁祸首,但是使用pry进行调试可能会帮助您找到它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24871213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档