2016-05-30 35 views
0

我是Rails的新手,我發現這個寶石郵箱用於在網站用戶之間發送消息。我無法編寫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 

什麼我需要做的,實現這些?

回答

0

我不知道你在談論的寶石。但是,一般來說,你可以在Rails中做這樣的事情。

假設你有一個模式消息,與name爲一列,你可以這樣做:

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

其中params[:name]可能不是「收件箱」或「已發送」。