【问题标题】:Heroku deployment of Rails application failing with phony_normalizeRails 应用程序的 Heroku 部署因 phony_normalize 而失败
【发布时间】:2013-02-06 00:53:25
【问题描述】:

我是 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 上的 User 模型没有找到 :phone 属性,尽管它在 attr_accessible 方法和数据库中。有谁知道发生了什么?我在网上找不到任何关于 Heroku 和 phony_rails 的信息。

【问题讨论】:

    标签: ruby-on-rails heroku


    【解决方案1】:

    所以看来我真的不了解 Heroku 部署。问题是我在部署到 Heroku 后没有迁移我的数据库(我想我认为这会自动发生)。在我发现关于 https://gist.github.com/njvitto/362873>这里一切正常。

    【讨论】:

    • 是的,很常见。即使在使用 heroku 多年后,我也经常忘记运行迁移并重新启动应用程序
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 2016-10-20
    • 2021-01-17
    • 2017-12-17
    • 2015-02-28
    • 2018-08-21
    相关资源
    最近更新 更多