我使用mailboxer gem,我可以发送和接收来自同一用户的消息(self)dexter可以向dexter发送消息,但是当我以dexter2登录并向dexter发送消息时,我得到未定义的方法错误,当我单击back按钮并刷新对话时,消息就在那里,因此正在发送消息,但我一直收到
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 %>
最佳答案
对于我在文档中看到的内容,您应该在模型中定义此方法:
def mailboxer_email(object)
#return the model's email here
end
这将确保您的模型具有Mailboxer识别资源所需的内容,您可以查看文档here
初始化器(config/initializers/mailboxer.rb):
Mailboxer.setup do |config|
# ...
#Configures the methods needed by mailboxer
config.email_method = :email
end
关于ruby-on-rails - Rails邮箱未定义方法`mailboxer_email',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23072684/