2

私はメールボックスのgemを使用しています。同じユーザー(自己)とメッセージを送受信できます。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 %>    
4

1 に答える 1