我按照本教程在y rails项目中添加了messagerie。
一切似乎都很好,但我点击了"已发送链接"部分消息出错。
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"
我真的不明白,这里有一些代码:
显示#view
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-body">
<%= render partial: 'messages' %>
</div>
</div>
</div>
这是部分_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 %>
我将部分_messages.html.erb放在app/views/conversations/_messages.htm.erb
感谢您的帮助
已发送链接的路径为mailbox_sent GET /mailbox/sent(.:format) mailbox#sent
,链接
<li class="<%= active_page(:sent) %>">
<%= link_to mailbox_sent_path do %>
这是对话控制器
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
对话控制器
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
视图为<%= render partial: 'mailbox/folder_view', locals: { is_conversation: false, messages: @inbox } %>
部分文件夹是
<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>