2014-04-15 142 views
1

我使用mailboxer寶石,我可以發送和接收消息,並從同一個用戶(個體)德克斯特可以發送消息給德克斯特,但是當我登錄爲dexter2和發送消息到德克斯特我得到了一個未定義的方法錯誤,當我點擊後退按鈕,並刷新了談話,這些消息是有這麼正在發送的消息,但我不斷收到導軌mailboxer未定義的方法`mailboxer_email」

undefined method 'mailboxer_email" for #<User:0x007f6ed0907040> 

messages_controller:

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 %>  

回答

7

對於我在讀您應該在您的模型中定義此方法的文檔:

def mailboxer_email(object) 
#return the model's email here 
end 

這將確保你的模型具有mailboxer需要識別的資源是什麼,你可以查看文檔here

初始化程序(配置/初始化/ mailboxer.rb):

Mailboxer.setup do |config| 
    # ... 
    #Configures the methods needed by mailboxer 
    config.email_method = :email 
end 
+0

我見,我將如何返回該值? – franklinexpress

+0

你只是做'object.email'或者你甚至可以定義哪些方法mailboxer將在初始化(配置/初始化/ mailboxer.rb)我編輯我的答案,以反映變化使用。 –

+0

'object.email'沒有給我的方法錯誤「電子郵件」,被撫摸這個部分,如果我把字符串「[email protected]」的電子郵件發送,我似乎無法得到一個返回值,雖然和我確實有電子郵件字段 – franklinexpress

相關問題