Missing partial with Mailboxer Gem

旧街凉风 提交于 2019-12-11 10:38:10

问题


I follow this tutorial to add a messagerie in y rails project.

All seems fine but I click on the "Sent link" There is an error with the partial message.

Missing partial mailbox/_messages, application/_messages with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}.
* "/Users/baptiste/code/BaptisteB/bosszzd/app/views"
  * "/Users/baptiste/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mailboxer-0.13.0/app/views"
  * "/Users/baptiste/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/devise-3.5.6/app/views"

I don't really understand, here some code :

Show#view

<div class="col-md-8">
  <div class="panel panel-default">
     <div class="panel-body">
       <%= render partial: 'messages' %>
     </div>
   </div>
</div>

Here is the partial _messages.html.erb

<% @receipts.each do |receipt| %>
    <% message = receipt.message %>
    <div class="media">
      <div class="media-left">
        <!-- user avators can go here -->
        <a href="#">
          <img class="media-object" src="http://placehold.it/64x64" alt="...">
        </a>
      </div>
      <div class="media-body">
        <h4 class="media-heading">
          <%= message.sender.first_name %> <%= message.sender.last_name[0] %> <br>
          <small><b>Subject: </b><%= message.subject %></small><br>
          <small><b>Date: </b><%=  message.created_at.strftime("%A, %b %d, %Y at %I:%M%p") %></small>
        </h4>
        <%= message.body %>
      </div>
    </div>
<% end %>

I place the partial _messages.html.erb in app/views/conversations/_messages.htm.erb

Thank you for your help

The path of the Sent link is mailbox_sent GET /mailbox/sent(.:format) mailbox#sent

and the link is

<li class="<%= active_page(:sent) %>">
    <%= link_to mailbox_sent_path do %>

Here is conversations controller

class ConversationsController < ApplicationController

  before_action :authenticate_user!

  def index
    @receipts = Receipt.all
  end

  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

MailboxController

class MailboxController < ApplicationController

  before_action :authenticate_user!

  def inbox
    @inbox = mailbox.inbox
    @active = :inbox
  end

  def sent
    @sent = mailbox.sentbox
    @active = :sent
  end

  def trash
    @trash = mailbox.trash
    @active = :trash
  end

end

Conversations Controller

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

The view is <%= render partial: 'mailbox/folder_view', locals: { is_conversation: false, messages: @inbox } %>

The partial folder is

    <ul class="nav nav-pills nav-stacked">
  <li class="<%= active_page(:inbox) %>">
    <%= link_to mailbox_inbox_path do  %>
        <span class="label label-danger pull-right"><%=unread_messages_count%></span>
        <em class="fa fa-inbox fa-lg"></em>
        <span>Inbox</span>
    <% end %>
  </li>
  <li class="<%= active_page(:sent) %>">
    <%= link_to mailbox_sent_path do %>

        <em class="fa fa-paper-plane-o fa-lg"></em>
        <span>Sent</span>
    <% end %>
  </li>

  <li class="<%= active_page(:trash) %>">
    <%= link_to mailbox_trash_path do %>
        <em class="fa fa-trash-o fa-lg"></em>
        <span>Trash</span>
    <% end %>
  </li>
</ul>

来源:https://stackoverflow.com/questions/36374798/missing-partial-with-mailboxer-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!