Ruby 在 rails。邮箱发送消息按钮
Ruby on rails. Mailboxer send message button
我在使用邮箱 gem 发送消息按钮时遇到问题。我将本教程用作指南“http://josephndungu.com/tutorials/private-inbox-system-in-rails-with-mailboxer”,其中与许多其他教程一样,您必须从所有用户列表中选择收件人。
我想要一个按钮来直接发送没有列表的消息,所以我在页面上制作了一个 'send user a message' 按钮,将用户 ID 传递给新的对话表单。
邮件未发送,仅显示在发件人的发件箱中。
这是我的代码:
<%= link_to '', new_conversation_path(:recipients_id => @user.id), class: 'send-message-icon' %>
也尝试过:
<%= link_to '', new_conversation_path(:recipients_id => @user), class: 'send-message-icon' %>
_form:(正确的用户ID显示在文本框中。我稍后会删除文本框)
<%= form_for :conversation, url: :conversations, html: { class: "" } do |f| %>
<div class="form-group">
<%= f.label :recipients %>
<%= f.text_field :recipients, :value => params[:recipients_id]%>
</div>
<div class="form-group">
<%= f.label :subject %>
<%= f.text_field :subject, placeholder: "Subject", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :message %>
<%= f.text_area :body, class: 'form-control',placeholder: "Type your message here", rows: 4 %>
</div>
<%= f.submit "Send Message", class: "btn btn-success" %>
控制器:
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
用户模型:
acts_as_messageable
before_destroy { messages.destroy_all }
我不明白为什么它不起作用。如有任何建议,我们将不胜感激。
经过 #$%"#"$%#$@ 的数小时后,我开始工作了。
从以下位置发送消息 link:
<%= link_to '', new_conversation_path(:recipient_id => @user.id), class: 'send-message-icon' %>
_表格:
<%= form_for :conversation, url: :conversations, html: { class: "" } do |f| %>
<div class="form-group">
<%= f.label :recipients %>
<%= hidden_field_tag(:recipient_id, "#{@user.id}") %></div>
<div class="form-group">
<%= f.label :subject %>
<%= f.text_field :subject, placeholder: "Subject", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :message %>
<%= f.text_area :body, class: 'form-control',placeholder: "Type your message here", rows: 4 %>
</div>
<%= f.submit "Send Message", class: "btn btn-success" %>
<% end %>
控制器:
def new
@user = User.find_by(id: params[:recipient_id])
end
def create
recipients = User.find_by(id: params[:recipient_id])
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
我在使用邮箱 gem 发送消息按钮时遇到问题。我将本教程用作指南“http://josephndungu.com/tutorials/private-inbox-system-in-rails-with-mailboxer”,其中与许多其他教程一样,您必须从所有用户列表中选择收件人。
我想要一个按钮来直接发送没有列表的消息,所以我在页面上制作了一个 'send user a message' 按钮,将用户 ID 传递给新的对话表单。
邮件未发送,仅显示在发件人的发件箱中。
这是我的代码:
<%= link_to '', new_conversation_path(:recipients_id => @user.id), class: 'send-message-icon' %>
也尝试过:
<%= link_to '', new_conversation_path(:recipients_id => @user), class: 'send-message-icon' %>
_form:(正确的用户ID显示在文本框中。我稍后会删除文本框)
<%= form_for :conversation, url: :conversations, html: { class: "" } do |f| %>
<div class="form-group">
<%= f.label :recipients %>
<%= f.text_field :recipients, :value => params[:recipients_id]%>
</div>
<div class="form-group">
<%= f.label :subject %>
<%= f.text_field :subject, placeholder: "Subject", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :message %>
<%= f.text_area :body, class: 'form-control',placeholder: "Type your message here", rows: 4 %>
</div>
<%= f.submit "Send Message", class: "btn btn-success" %>
控制器:
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
用户模型:
acts_as_messageable
before_destroy { messages.destroy_all }
我不明白为什么它不起作用。如有任何建议,我们将不胜感激。
经过 #$%"#"$%#$@ 的数小时后,我开始工作了。
从以下位置发送消息 link:
<%= link_to '', new_conversation_path(:recipient_id => @user.id), class: 'send-message-icon' %>
_表格:
<%= form_for :conversation, url: :conversations, html: { class: "" } do |f| %>
<div class="form-group">
<%= f.label :recipients %>
<%= hidden_field_tag(:recipient_id, "#{@user.id}") %></div>
<div class="form-group">
<%= f.label :subject %>
<%= f.text_field :subject, placeholder: "Subject", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :message %>
<%= f.text_area :body, class: 'form-control',placeholder: "Type your message here", rows: 4 %>
</div>
<%= f.submit "Send Message", class: "btn btn-success" %>
<% end %>
控制器:
def new
@user = User.find_by(id: params[:recipient_id])
end
def create
recipients = User.find_by(id: params[:recipient_id])
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