Heroku部署的Rails应用程序失败了,使用了phony_normalize

时间:2013-02-05 16:19:58

标签: ruby-on-rails heroku

我是Heroku部署Ruby on Rails应用程序的新手,我遇到了一个非常奇怪的情况。我试图使用phony_rails gem部署应用程序。这在我的本地(Windows)机器上在开发和生产(使用Postgres进行生产)中部署得很好,但在Heroku上部署时失败了。具体来说,这是Heroku的堆栈跟踪的开始。

2013-02-05T16:05:26+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/phony_rails-0.1.12/lib/phony_rails.rb:74:in `block in phony_normalize': No attribute phone found on User (PhonyRails) (ArgumentError)
2013-02-05T16:05:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/phony_rails-0.1.12/lib/phony_rails.rb:73:in `each'
2013-02-05T16:05:26+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/phony_rails-0.1.12/lib/phony_rails.rb:73:in `phony_normalize'
2013-02-05T16:05:26+00:00 app[web.1]:   from /app/app/models/Users/user.rb:89:in `<class:User>'
2013-02-05T16:05:26+00:00 app[web.1]:   from /app/app/models/Users/user.rb:55:in `<top (required)>'

有问题的代码,在user.rb的第89行就是这个

phony_normalize :phone, :default_country_code => 'US'

在浏览了phony_rails的源代码之后,我发现了以下内容(ArgumentError在第74行)

# Use this method on the class level like:
#   phony_normalize :phone_number, :fax_number, :default_country_code => 'NL'
#
# It checks your model object for a a country_code attribute (eg. 'NL') to do the normalizing so make sure
# you've geocoded before calling this method!
def phony_normalize(*attributes)
  options = attributes.last.is_a?(Hash) ? attributes.pop : {}
  options.assert_valid_keys :country_code, :default_country_code, :as
  if options[:as].present?
    raise ArgumentError, ':as option can not be used on phony_normalize with multiple attribute names! (PhonyRails)' if attributes.size > 1
    raise ArgumentError, "'#{options[:as]}' is not an attribute on #{self.name}. You might want to use 'phony_normalized_method :#{attributes.first}' (PhonyRails)" if not self.attribute_method?(options[:as])
  end
  attributes.each do |attribute|
    raise ArgumentError, "No attribute #{attribute} found on #{self.name} (PhonyRails)" if not self.attribute_method?(attribute)
    # Add before validation that saves a normalized version of the phone number
    self.before_validation do
      set_phony_normalized_numbers(attributes, options)
    end
  end
end

以下是来自用户模型的attr_accesible调用

attr_accessible :email, :name, :password, :password_confirmation, :rights, :right_ids,
:address_one, :address_two, :city, :state, :zip, :phone, :institutions, :institution_ids

看来我在Heroku上的用户模型没有找到:phone属性,尽管它在attr_accessible方法和数据库中都有。有没有人知道发生了什么?我无法在网上找到关于Heroku和phony_rails的任何内容。

1 个答案:

答案 0 :(得分:1)

所以看起来我真的不懂Heroku部署。问题是我在部署到Heroku后没有迁移我的数据库(我想我认为这会自动发生)。在我找到关于https://gist.github.com/njvitto/362873>的内容之后,这一切都奏效了。

相关问题