2016-01-23 71 views
0

我无法使发送消息按钮与邮箱gem一起工作。我将本教程用作指南'http://josephndungu.com/tutorials/private-inbox-system-in-rails-with-mailboxer',与其他许多人一样,您必须从所有用户的列表中选择收件人。红宝石轨道上。邮箱发送消息按钮

我想要一个按钮,直接发送没有列表的消息,因此我在页面上发送了“发送用户消息”按钮,将用户标识传递给新的对话表单。

邮件没有发送,只在发送者发送的邮箱中显示。

这里是我的代码:

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

我不明白为什么它不工作。任何建议,将不胜感激,谢谢。

回答

0

在#$%“#”$%#$ @周围数小时之后,我得到了它的工作。

<%= link_to '', new_conversation_path(:recipient_id => @user.id), class: 'send-message-icon' %> 

_form:

<%= 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 
随时随地

发送消息链接