[英]Why can't I get the Rails Mailboxer gem working?
I am using the mailboxes gem in rails 4. I am trying to make it so that when A user goes to another user's profile, they click on a button on that profile that sends the second user a message. 我正在Rails 4中使用邮箱gem。我试图这样做,以便当一个用户转到另一个用户的个人资料时,他们单击该个人资料上的按钮,该按钮向第二个用户发送消息。 For example, A goes to B's profile and clicks the message button. 例如,A转到B的个人资料,然后单击消息按钮。 B will then get a message from a. 然后,B将收到来自a的消息。 On the profile page, I have the following code: 在个人资料页面上,我有以下代码:
<%=current_user.send_message(@user, "Body", "subject") %>
I've also tried placing the code above in a link_to tag but that does not work. 我也尝试过将上面的代码放在link_to标记中,但这不起作用。 On the Receive messages page, I have the following code that I got from the documentation: 在“接收消息”页面上,我有以下从文档中获取的代码:
Conversations:
<%= current_user.mailbox.conversations %>
Inbox:
<%= current_user.mailbox.inbox %>
But nothing appears in either the inbox code or the conversations code. 但是收件箱代码或对话代码中均未显示任何内容。 Please help. 请帮忙。 Thanks. 谢谢。
If you want your code to be evaluated use <%
. 如果要评估代码,请使用<%
。 <%=
is for writing stuff out on the page. <%=
用于在页面上写东西。 Also the .send_message method really shouldn't be in your view. 而且,您实际上不应该使用.send_message方法。 Create an action in your controller, or create whole service object and make it responsible for messaging. 在控制器中创建一个动作,或创建整个服务对象并使其负责消息传递。
One thing is that code like this really doesn't belong in a view. 一件事就是这样的代码确实不属于视图。 But more importanlty, you should be calling it, only if user click a link. 但是,更重要的是,仅当用户单击链接时,才应调用它。 So, simple solution would be: 因此,简单的解决方案是:
current_user.send_message(@user, "Body", "subject")
into your newly created action, use redirect if you don't want a template for this action 将行current_user.send_message(@user, "Body", "subject")
放入您新创建的操作中,如果您不需要此操作的模板,请使用重定向
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.