1

I'm new to Heroku deployment of my Ruby on Rails application, and I'm running into a very strange situation. I'm attempting to deploy an application with the phony_rails gem. This deploys fine on my local (Windows) machine in both development and production (production using Postgres), but fails when deploying on Heroku. Specifically, here is the beginning of the stack trace from 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)>'

The offending code, on line 89 of user.rb is this

phony_normalize :phone, :default_country_code => 'US'

After looking through the source of phony_rails, I found the following (the ArgumentError is on line 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

Here is the attr_accesible call from the User model

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

It would appear that my User model on Heroku isn't finding the :phone attribute, although it's in both the attr_accessible method and it's in the database. Does anyone have any idea what's going on? I can't find anything on the web concerning Heroku and phony_rails.

1 Answer 1

1

So it would appear I really don't understand Heroku deployment. The problem was that I was not migrating my db after deploying to Heroku (I guess I thought that would happen automatically). After I found about about https://gist.github.com/njvitto/362873>here it all worked.

1
  • yeah, very common. even after years of using heroku, I often forget to run the migrations and restart the app Feb 5, 2013 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.