2

我有邮箱 gem 设置,当我访问 /conversations 时,我收到一个undefined method参与者' ` 错误指向带有索引的对话控制器。我向 index 操作添加了一个会话实例变量,它将包含所有用户的收件箱消息。

有人能发现我的定义哪里出错了吗?

对话控制器:

 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
4

1 回答 1

1

我终于可以重现您的问题,我通过运行解决了它:

rails g mailboxer:install

rake db:migrate

您可能需要对conversations数据库中的现有表做一些事情。

于 2014-02-26T16:05:54.170 回答