0

I have created a simple model for handling a contact form:

 class ContactForm
   include ActiveAttr::Model

  attribute :name
  attribute :email
  attribute :message

  attr_accessible :name, :email, :message

  validates_presence_of :name, :email, :message
  validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]    {2,4}$/i
end

It works fine on the development environment, but gives me an error on the production server, logged in the unicorn log:

E, [2013-01-26T18:15:42.724973 #8940] ERROR -- : uninitialized constant ContactForm::ActiveAttr (NameError)

Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.11'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'pg'
gem 'bootstrap-sass'
gem 'font-awesome-sass-rails'
# gem 'acts_as_tree', :git => 'git://github.com/amerine/acts_as_tree.git'
gem 'closure_tree'
gem 'kaminari'
gem 'friendly_id'
gem 'slim'
gem 'gmaps4rails'
gem 'devise'
gem 'omniauth'
gem 'oauth2'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'simple_form'
gem 'pg_search'
gem 'stamp'
gem 'acts-as-taggable-on', '~> 2.3.1'
gem 'rmagick'
gem 'carrierwave'
gem 'active_attr'
gem 'select2-rails'
# gem 'roo'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby
  gem 'uglifier', '>= 1.0.3'
  gem 'compass-rails'
end

group :development do 
  gem "better_errors"
  gem "binding_of_caller"
  gem 'guard'
  gem 'letter_opener'
end

group :test do 
  gem 'minitest'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
gem 'unicorn'

# Deploy with Capistrano
gem 'capistrano'

# To use debugger
# gem 'debugger'

gem 'bullet', :group => :development
gem 'rack-mini-profiler'
AlexBrand
  • 11,971
  • 20
  • 87
  • 132

2 Answers2

2

I had the same problem and the fix for me was to specify the version of active_attr in my gemfile.

gem 'active_attr', '0.7.0'

I found an issue on GitHub where someone else had the same problem here.

Undo
  • 25,519
  • 37
  • 106
  • 129
jshaffer
  • 21
  • 3
0

I have the same problem in development environment. I followed this step-by-step tutorial https://github.com/thomasklemm/email_form_rails.

When I try to create a new message in console I get :

m=Message.new
NameError: uninitialized constant Message::ActiveAttr

I use Rails 3.2.1, active_attributes gem version is 0.0.1.

EDIT

My fault it seems I made a mistake when installing the gem (not the good one)

change gemfile from gem 'active_attributes','0.0.1'

to gem 'active_attr', '0.0.7'

Now it seems to work...

phron
  • 1,795
  • 17
  • 23