codeforbtv / foodrescue

2 stars 3 forks source link

Capture user ip #29

Closed benglass closed 10 years ago

benglass commented 10 years ago

I added code to store the user's ip in the database but I cannot get it working on heroku.

I generate a migration which adds a string{45} field called respondent_ip which I can tell is working because I can connect to the postgresql db via

heroku pg:psql --app food-rescue gray                                                                                                              

When I look at the db it has the field but when I try to post step 1 I get the following error

2014-06-06T00:35:11.270337+00:00 heroku[router]: at=info method=POST path=/type host=food-rescue.herokuapp.com request_id=4cdf7d7b-2b96-4ebd-aa35-872163d8c17f fwd="71.181.70.238" dyno=web.1 connect=2ms service=18ms status=500 bytes=1708 2014-06-06T00:35:11.267257+00:00 app[web.1]: NoMethodError (undefined method respondent_ip=' for #<SurveyResponse:0x007f3e0557c8b8>): 2014-06-06T00:35:11.267259+00:00 app[web.1]: app/controllers/pages_controller.rb:43:inblock in type_post' 2014-06-06T00:35:11.254967+00:00 app[web.1]: Started POST "/type" for 71.181.70.238 at 2014-06-06 00:35:11 +0000 2014-06-06T00:35:11.267264+00:00 app[web.1]: 2014-06-06T00:35:11.267266+00:00 app[web.1]: 2014-06-06T00:35:11.267262+00:00 app[web.1]: app/controllers/pages_controller.rb:42:in `type_post' 2014-06-06T00:35:11.259386+00:00 app[web.1]: Processing by PagesController#type_post as HTML 2014-06-06T00:35:11.265787+00:00 app[web.1]: Completed 500 Internal Server Error in 6ms 2014-06-06T00:35:11.259823+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"LkFkKs3PEA+ceVNbKyi0tsnXTWHMjP6K6Iu84jyWDZ4=", "zip"=>"05158", "lat"=>"42.995639999999995", "long"=>"-71.45478899999999", "food_description"=>"lasagna", "answer"=>"1"} 2014-06-06T00:35:11.267253+00:00 app[web.1]:

I dont understand the NoMethodError since none of the other properties have explicitly defined methods for them in the SurveyResponse model and since the field is in the database. I'm sure its just something about rails I am missing but I successfully generated the completed migration and deployed that.

@alexch @Dangeranger thoughts?

benglass commented 10 years ago

I should add I tested all this code locally without issue. My only thought at this point is it has something to do with using a different database driver in production but that doesnt seem to make sense.

benglass commented 10 years ago

Serious wtf. I rolled back the change in heroku and then tried to redeploy a few hours later. It said it was already up to date. I went and checked the app and all the sudden it was working with the new codebase (ie ips were being saved properly). Nothing in the code changed.. im assuming this is a heroku caching issue or something with it requiring a restart? Seems like perhaps the same issue these folks are experiencing http://stackoverflow.com/questions/7373039/getting-nomethoderror-undefined-method-name-for-nilnilclass-when-creating-a

Im assuming there is just something step for deployments that involve a migration which I did wrong? Running git push heroku did not run migrations. I had to run heroku run rake:db:migrate after that. After that everything was broken with a NoMethodError. Any suggestions on what is wrong in that process Id love to hear.

benglass commented 10 years ago

It seems that heroku requires a restart after migrations

After running a migration you’ll want to restart your app with heroku restart to reload the schema and pickup any schema changes.

from: https://devcenter.heroku.com/articles/rake