0

我创建了一个简单的模型来处理联系表:

 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

它在开发环境中运行良好,但在生产服务器上给我一个错误,记录在 unicorn 日志中:

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

宝石文件

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'
4

2 回答 2

2

我遇到了同样的问题,我的解决方法是active_attr在我的gemfile.

gem 'active_attr', '0.7.0'

我在 GitHub 上发现了一个问题,其他人在这里遇到了同样的问题。

于 2013-07-14T21:47:53.850 回答
0

我在开发环境中遇到了同样的问题。我按照这个分步教程https://github.com/thomasklemm/email_form_rails

当我尝试在控制台中创建新消息时,我得到:

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

我使用 Rails 3.2.1,active_attributes gem 版本是 0.0.1。

编辑

我的错,似乎我在安装 gem 时犯了一个错误(不是好的那个)

从 gem 'active_attributes','0.0.1' 更改 gemfile

到 gem 'active_attr', '0.0.7'

现在它似乎工作......

于 2013-01-27T16:31:22.193 回答