【问题标题】:Ruby on rails. Mailboxer send message button红宝石在铁轨上。邮箱发送消息按钮
【发布时间】:2016-01-23 17:34:56
【问题描述】:

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

我想要一个不带列表直接发送消息的按钮,因此我在页面上创建了一个“向用户发送消息”按钮,将用户 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 }

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

【问题讨论】:

    标签: ruby-on-rails select button mailboxer


    【解决方案1】:

    经过几个小时的#$%"#"$%#$@ing 之后,我得到了它的工作。

    从任何地方发送消息链接:

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

    【讨论】:

      猜你喜欢
      • 2011-07-13
      • 2016-03-21
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-09
      • 2017-03-26
      • 1970-01-01
      相关资源
      最近更新 更多