undefined local variable or method `acts_as_messageable' #38

JoeKueser opened this Issue Apr 4, 2012 · 27 comments

I followed the docs, but am getting an error stating "undefined local variable or method `acts_as_messageable'" when I try to run my app or bring up the Rails console.

If it matters, my User model is a "standard" Devise user, and here's the relevant code.

class User < ActiveRecord::Base

  has_one :project_professional
  has_many :projects
  has_many :bids
  has_many :ratings, through: :reviews

  after_create :mark_approved

  ROLES = %w[admin client project_professional moderator]
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :omniauthable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :roles, :user_type

Using the default Mailboxer initializer:

Mailboxer.setup do |config|

  #Configures if you applications uses or no the email sending for Notifications and Messages
  config.uses_emails = true

  #Configures the default from for the email sent for Messages and Notifications of Mailboxer
  config.default_from = "no-reply@mailboxer.com"

  #Configures the methods needed by mailboxer
  config.email_method = :mailboxer_email
  config.name_method = :name

  #Configures if you use or not a search engine and wich one are you using
  #Supported enignes: [:solr,:sphinx] 
  config.search_enabled = false
  config.search_engine = :solr

And the relevant bits of my Gemfile

gem 'rails', '3.2.2'
gem 'haml'
gem 'devise', '~> 2.0.0'
gem "omniauth-facebook"
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
gem 'cancan'
gem 'paperclip', '~> 2.5.1'
gem 'acts-as-taggable-on'
gem 'forem', :git => "git://github.com/radar/forem.git"
gem 'redcarpet'
gem 'best_in_place'
gem 'simple_form'
gem 'gmaps4rails'
gem "kaminari"
gem "will_paginate"

gem 'mailboxer', git: 'git://github.com/ging/mailboxer.git'

Is my issue Rails 3.2.2? Any tips on how to resolve this would be greatly appreciated. Looks like a great gem.

mailboxer member

Let me create a simple app from zero and try to reproduce the error.

By the way, you don't need to use gem 'mailboxer', git: 'git://github.com/ging/mailboxer.git', Mailboxer is on rubygems, so you can use just gem 'mailboxer'.

mailboxer member

I have just created a pair of new applications from scratch creating a User scaffold with just the name and email. After that I just followed the install instructions as they are, with nothing different, added acts_as_messageable and run the app from console and everything seems ok.

Can you delete everything from mailboxer and reinstall again following the instruccions as they are? I mean, not installing the gem from github. If this still fails, I have another idea, but let's give it a try first


did you restart the server? everyone forgets once in a while :)


In config/initializers/rails_admin.rb, after

RailsAdmin.config do |config|

add this

include Mailboxer::Models::Messageable

This worked for me.

mailboxer member

I will assume @JoeKueser solved the issue as he vanished.

If the bug persists, feel free to reopen it.

@Roendal Roendal closed this Apr 23, 2012

@computeus Your solution worked.
should it be added to the Installation instructions?

@Roendal Roendal reopened this May 1, 2012
mailboxer member

I will reopen the issue to look for a solution as soon as I have some time.

mailboxer member

@computeus, @gaaady, are you using rails 3.2?


No, Rails 3.1


I am using 3.2.2

mailboxer member

It makes no sense for me. This include is already present in the gem https://github.com/ging/mailboxer/blob/master/lib/mailboxer/engine.rb#L15

Any ideas on why this is happening?


I do not have much knowledge but probably, maybe while rails admin initializes, it did not load/initialize Mailboxer gem for its inner use.

Maybe asking to rails admin developers is a good idea.

atd commented May 5, 2012

I agree with @computeus

It seems that RailsAdmin is doing stuff that requires loading the User class before Mailboxer's initializer is able to define the acts_as_messageable method https://github.com/ging/mailboxer/blob/master/lib/mailboxer/engine.rb#L13

I would try to declare mailboxer before rails_admin in the Gemfile.


As @atd suggested, I was able to get everything to work by declaring mailboxer before rails in the Gemfile.

atd commented Jun 7, 2012



I have same error when I try to run

RAILS_ENV=production rake db:migrate

When I run

RAILS_ENV=development rake db:migrate


RAILS_ENV=test rake db:migrate

it works properly. How can it be?

My Gemfile:

gem 'rails', '3.2.8'
gem 'pg'
gem 'bigdecimal'

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
  gem "bootstrap-sass", "~>"
  gem "select2-rails"
  gem "jqcloud-rails"

gem 'jquery-rails'
gem "haml-rails"
gem "devise"
gem 'devise-async'
gem "cancan"
gem 'russian', '~> 0.6.0'
gem 'simple_form'
gem 'acts-as-taggable-on', '~> 2.3.1'
gem "friendly_id", "~> 4.0.1"
gem 'kaminari'
gem 'bitmask_attributes'
gem 'enumerize'
gem "rails-settings-cached"
gem 'sitemap_generator'
gem 'exception_notification'
gem 'mailboxer'
gem 'unicorn'
gem 'capistrano'
gem "capistrano-resque", "~> 0.0.6"
gem 'resque', :require => 'resque/server'
gem 'resque-scheduler', :require => 'resque_scheduler'
gem 'resque_mailer'

group :development do
  gem "letter_opener"

group :test, :development do
  gem "rspec-rails", "~> 2.11.0"
  gem "factory_girl_rails", "~> 3.2.0"
  gem "spork-rails", "~> 3.2.0"
  gem "guard-rspec", "~> 0.7.0"
  gem "guard-spork"

group :test do
  gem "faker", "~> 1.0.1"
  gem "capybara", "~> 1.1.2"
  gem "database_cleaner", "~> 0.7.2"
  gem "launchy", "~> 2.1.0"
  gem "shoulda-matchers"
  gem 'minitest'
  gem "headless"

I solved my problem

class User < ActiveRecord::Base

  include Mailboxer::Models::Messageable




@Roendal Roendal closed this Dec 13, 2012

I tried all the suggestions above with no luck. I am using mailboxer 0.10.2. Could anyone solve this issue?


same issue here after updating from 0.9.0 to 0.10.2. The suggestion in #38 (comment) worked for 0.9.0, so I'm locking mailboxer to that version for the moment.


Thanks. I did the same


I have mailboxer(0.11.0), rails4 and rails_admin(0.5.0) in my Gemfile

none of the previously listed solutions helped me to solve this exception.

I got it fixed with adding extend Mailboxer::Models::Messageable::ActiveRecord manually to my user model.



@nfedyashev fixed worked for me, the problem came right after I added additional field to devise and overriding some methods to make strong parameter work.....


@nfedyashev fixed worked for me too


now it is extend Mailboxer::Models::Messageable::ActiveRecordExtension


Thanks @musaffa . That works for me. The others weren't working.


Thanks, @musaffa. Also worked for me when I had a problem after adding a new config initializer file (for Envato double_entry).


This worked for me as well. I would include this in the README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment