Mailboxer Gem--Restrict messaging


Mailboxer allows you to connect multiple models as in the example from the gem page. <a href="https://github.com/mailboxer/mailboxer" rel="nofollow">Mailboxer Github page</a>


You can use Mailboxer in any other model and use it in several different models. If you have ducks and cylons in your application and you want to exchange messages as if they were the same, just add acts_as_messageable to each one and you will be able to send duck-duck, duck-cylon, cylon-duck and cylon-cylon messages.


How can we restrict messaging to only between duck-cylon and vice versa? So, only a duck can initiate a conversation and a cylon can reply? And, no duck-duck and cylon-cylon conversations are possible?


You could add a module to the models

class Duck < ActiveRecord::Base acts_as_messageable include mailboxer_filter end


class Cylon < ActiveRecord::Base acts_as_messageable include mailboxer_filter end

your module...

module MalboxerFilter def initiator? self.class == Duck end def replyer? self.class == Cylon end def send_message_filtered(beta, body, subject) self.send_message(beta, body, subject) if initiator? && beta.replyer? end def reply_to_sender_filtered(*args) self.reply_to_sender(*args) if replyer? end end

Then use send_message_filtered and reply_to_sender_filtered in your app. This can be more sophisticated if you need it... perhaps raise an exception if a Cylon attempts to initiate a message or a Duck attempts to reply.


  • How to select and click all html checkboxes?
  • End Conversation in Seam when the user leaves the page
  • dynamic casting?
  • Is there a list of all stock messaging apps package names for all Android phone constructors?
  • Why does my Rspec post :create invalid parameter controller test fail?
  • PHP: concatenation of multidimensional array elements
  • Restric user access to table using Sql Server 2008
  • Show outbound texts using SMSManager in the default android text application
  • Getting contents of square brackets, avoiding nested brackets
  • How to use Spring Integration 5 with Spring Boot 1.5.x
  • How to get multiple results from SQL query
  • iOS App Store ExecutionEngineException attempting to JIT compile
  • SwipeListView in Xamarin Form
  • Handle Authentication and Authorization in jax-rs webservice with cxf
  • Compiling Element Causes Input Caret Position to Move to End
  • How to share a database between ASP.NET MVC 5 application and .NET console application?
  • BizTalk Party not being resolved for incoming HL7v2 message
  • R h2o.glm - issue with max_active_predictors
  • Using SWIG with a build system [closed]
  • How to check if a string contains any string of a column in MySQL and vice versa?
  • Print character to a certain point on console in Python?
  • How do you keep a running instance for Google App Engine
  • py4j.protocol.Py4JJavaError when selecting nested column in dataframe using select statetment
  • Python 3.2.2, error(scripts to exe)
  • python mysqldb delete row
  • import scipy.sparse failed
  • Using $compile in a directive triggers AngularJS infinite digest error
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • Autofac with Web API 2 - Parameter-less constructor error
  • pillow imaging ImportError
  • Authentication in Play! and RestEasy
  • Django simple Captcha “No module named fields” error
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Is there a perl module to validate passwords stored in “{crypt}hashedpassword” “{ssha}hashedpassword
  • Meteor helpers not available in Angular template
  • Updating server-side rendering client-side
  • Statically linking a C++ library to a C# process using CLI or any other way
  • How to pass list parameters for each object using Spring MVC?
  • using HTMLImports.whenReady not working in chrome
  • sending mail using smtp is too slow