我是Heroku部署我的Ruby on Rails應用程序的新手,我遇到了一個非常奇怪的情況。我試圖用phony_rails gem部署一個應用程序。這在開發和生產(使用Postgres進行生產)的本地(Windows)機器上部署得很好,但在Heroku上部署時失敗。具體來說,這裏是Heroku堆棧跟蹤的開始。Heroku部署Rails應用程序失敗與phony_normalize
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的任何內容。
是的,很常見。即使經過多年使用heroku,我經常忘記運行遷移並重新啓動應用程序 –