我正在使用mailboxer gem,我可以向同一个用户(self)发送和接收消息 dexter 可以向 dexter 发送消息,但是当我以 dexter2 登录并向 dexter 发送消息时,当我单击后退按钮并刷新对话,消息在那里,所以消息正在发送,但我不断收到
undefined method 'mailboxer_email" for #<User:0x007f6ed0907040>
消息控制器:
class MessagesController < ApplicationController
def new
@user = User.find_by_username(params[:user])
@message = current_user.messages.new
结尾
# POST /message/create
def create
@recipient = User.find_by_username(params[:user])
current_user.send_message(@recipient, params[:body], params[:subject])
flash[:notice] = "Message has been sent!"
redirect_to :conversations
end
end
对话/show.html.erb
<%= conversation.subject %>
A conversation with
<% conversation.participants.each do |participant| %>
<% if participant != current_user %>
<%= participant.username%>
<% end %>
<% end %>
<%= content_tag_for(:li, conversation.receipts_for(current_user)) do |receipt| %>
<% message = receipt.message %>
<%= message.sender.username %>
<%= simple_format h message.body %>
Sent <%= conversation.updated_at.strftime("%a, %m/%e/%Y %I:%M %p") %>
<% end %>
<%= render 'messages/form', conversation: conversation %>
消息/表格
Reply:
<%= form_for :message, url: [:reply, conversation] do |f| %>
<%= f.text_area :body %>
<%= f.submit "Send Message", class: 'btn btn-primary' %>
<%= submit_tag 'Clear Reply Box', type: :reset, class: 'btn btn-danger' %>
<% end %>
消息/new.html.erb
Send a message to
<%= @user.username %>
<%= form_tag({controller: "messages", action: "create"}, method: :post) do %>
<%= label_tag :subject %>
<%= text_field_tag :subject %>
<%= label :body, "Message text" %>
<%= text_area_tag :body %>
<%= hidden_field_tag(:user, "#{@user.username}") %>
<%= submit_tag 'Send message' %>
<% end %>