添加gem邮箱的搜索功能

时间:2016-05-30 15:20:04

标签: ruby-on-rails ruby ruby-on-rails-4

我是Rails的新手,我发现这个gem邮箱用于在网站用户之间发送邮件。我无法为inboxsent编写搜索功能。

会话控制器

class ConversationsController < ApplicationController
  before_action :authenticate_user!

  def new
  end

  def create
    recipients = User.where(id: conversation_params[:recipients])
    conversation = current_user.send_message(recipients, conversation_params[:body], conversation_params[:subject]).conversation
    flash[:success] = "Your message was successfully sent!"
    redirect_to conversation_path(conversation)
  end

  def show
    @receipts = conversation.receipts_for(current_user)
    # mark conversation as read
    conversation.mark_as_read(current_user)
  end

  def reply
    current_user.reply_to_conversation(conversation, message_params[:body])
    flash[:notice] = "Your reply message was successfully sent!"
    redirect_to conversation_path(conversation)
  end

  def trash
    conversation.move_to_trash(current_user)
    redirect_to mailbox_inbox_path
  end

  def untrash
    conversation.untrash(current_user)
    redirect_to mailbox_inbox_path
  end

private

  def conversation_params
    params.require(:conversation).permit(:subject, :body,recipients:[])
  end

   def message_params
    params.require(:message).permit(:body, :subject)
  end
end

我需要做些什么来实现这些?

1 个答案:

答案 0 :(得分:0)

我不知道你在谈论的宝石。但是,一般来说,你可以在Rails中做这样的事情。

假设您有一个模型消息,并以name为列,您可以这样做:

Message.where("name like ?", params[:name])

其中params[:name]可以是“收件箱”或“已发送”。