I have a working rails app on my local machine. I updated my Heroku and started to test it. One of my views requires the controller to add elements to an array using unshift.
When I go to this view on the web, I get an error We're sorry, but something went wrong.
I went into $heroku logs and the most recent errors are:
2014-02-28T02:08:26.650021+00:00 app[web.1]: NoMethodError (undefined method `unshift' for #<ActiveRecord::AttributeMethods::Serialization::Attribute:0x007fe57862f588>):
2014-02-28T02:08:26.650021+00:00 app[web.1]: app/controllers/users_controller.rb:32:in `show'
Any ideas how to fix this?
my controller function looks like this:
#user.daily = #user.daily.unshift(day)
#user.daily is a serialized array
#Mhsmith21, if day is an object and if you are rails 4+ then my suggestion is to use build instead of unshift.
If you are using unshift to add the object on first position then use build and reverse the array.
As unshift does not work for ActiveRecord::Associations::CollectionProxy.
I have very strange error only in Rails production environment. In development works good. The logs show error in this line in my index.html.erb file.
This is the production log error:
ActiveRecord::RecordNotFound (Couldn't find Person without an ID):
app/views/seeds/index.html.erb:71:in `block in _app_views_seeds_index_html_erb__4016841983995682700_31529840'
app/views/seeds/index.html.erb:61:in `each'
app/views/seeds/index.html.erb:61:in `_app_views_seeds_index_html_erb__4016841983995682700_31529840'
app/controllers/seeds_controller.rb:17:in `index'
The line in my seed index file is this one:
<td><%= Person.find(seed.person_id).name %></td>
Before this line I query other data in the same way with foreign key and it works. When I check the sql table I see that the Seeds table has the person_id value.
Moreover, when I query the same thing via the rails console in production environment i receive the result without any problems. But when I load the page it shows me "The page you were looking for doesn't exist." and the production.log shows the error above... Any ideas what might be wrong?
Sorry guys after a whole day of coding by brain was not to good. The point is that in the middle of the table I had a NULL object for person and that was causing the error... Thank you for your time
I'm getting the following error
i created a new scaffold bid with few fields
when i tried to access localhost:3000/bids/new
i get following error
ActiveRecord::DangerousAttributeError in BidsController#new
save is defined by ActiveRecord
in server side i see this result:
Started GET "/bids/new" for 127.0.0.1 at 2013-09-07 12:52:43 +0530
Processing by BidsController#new as HTML
Refinery::Role Load (0.4ms) SELECT "refinery_roles".* FROM "refinery_roles" WHERE "refinery_roles"."title" = 'Refinery' LIMIT 1
Refinery::User Load (0.3ms) SELECT "refinery_users".* FROM "refinery_users" INNER JOIN "refinery_roles_users" ON "refinery_users"."id" = "refinery_roles_users"."user_id" WHERE "refinery_roles_users"."role_id" = 1
Completed 500 Internal Server Error in 779ms
ActiveRecord::DangerousAttributeError (save is defined by ActiveRecord):
app/controllers/bids_controller.rb:27:in `new'
app/controllers/bids_controller.rb:27:in `new'
what am i missing or is refinerycms mounted at / is overriding functions?
please help me
It Seems, you have defined some reserved ActiveRecord's attributes, If you did so, than you either have to change those or try something else. Just add a gem in your gemfile and the gem will take care of name collisions automatically.
gem 'safe_attributes'
hope it will help. Thanks.
I have solved my problem,
The problem is not with refinery cms
i created a field with name save:boolean
i changed it to save_x:boolean and now it works fine
I have a Ruby on Rails app that works fine locally with a sqlite3 database and can save and retrieve records without issue.
When deployed to Heroku at http://moviedata.herokuapp.com/ using a postgresql database, records are not saving even though it looks like the logs say they are. Records read from the db fine and data is displayed as expected.
The tailed logs for adding a record are:
2012-08-21T19:51:31+00:00 app[web.1]:
2012-08-21T19:51:31+00:00 app[web.1]:
2012-08-21T19:51:31+00:00 app[web.1]: Started POST "/" for 50.53.6.156 at 2012-08-21 19:51:31 +0000
2012-08-21T19:51:31+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"+BYQLzhrfDkUVW8UaHikHpmtGHxpeQ/yF4VByHh9m1I=", "movie"=>{"title"=>"The Running Man", "description"=>"A documentary about a public execution game show.", "year"=>"1987", "genre"=>"science fiction"}, "commit"=>"Create Movie"}
2012-08-21T19:51:31+00:00 app[web.1]: Processing by MoviesController#index as HTML
2012-08-21T19:51:31+00:00 app[web.1]: Rendered movies/index.html.erb within layouts/application (5.1ms)
2012-08-21T19:51:31+00:00 app[web.1]: Completed 200 OK in 9ms (Views: 6.7ms | ActiveRecord: 0.9ms)
2012-08-21T19:51:31+00:00 heroku[router]: POST moviedata.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=17ms status=200 bytes=3479
The 'heroku pg' command shows the same number of rows (11) on the postgres database after a record is added.
This is a simple app I built to learn Rails and the Heroku platform. To reproduce this, just visit http://moviedata.herokuapp.com/ and click "New Movie", enter some junk data in the form, and hit "create movie". The record should be saved and show up in the list on the front page, but it doesn't.
Is there perhaps something I have to turn on, configure, or activate in order to be able to write to the postgres database? Seems very strange to me that it could be read from but not written to. Any better way to troubleshoot than the logs?
Locally I'm using Ruby 1.9.3, Rails, 3.2.8, PostgreSQL 9.1.5, SQLite 3.7.9, Heroku Toolbelt 2.30.3.
Edit/Update: I switched the local version to use psql. It also experiences the same problem where records are not saved. With the user set to log_statement='all' The log in at /var/log/postgresql/posgresql-9.1.main.log shows lots of selects, but when the record add is attempted, the log shows the database never being hit.
Foreman shows the data being posted, like so:
22:38:03 web.1 | Started POST "/" for 127.0.0.1 at 2012-08-21 22:38:02 -0700
22:38:03 web.1 | Processing by MoviesController#index as HTML
22:38:03 web.1 | Parameters: {"utf8"=>"✓", "authenticity_token"=>"0AyxRbwl/Kgi05uI1KX8uxVUJjx9ylAA1ltdWgmunm4=", "movie"=>{"title"=>"Army of Darkness", "description"=>"A man fights the living dead using a boomstick.", "year"=>"1997", "genre"=>"horror"}, "commit"=>"Create Movie"}
22:38:03 web.1 | Movie Load (0.8ms) SELECT "movies".* FROM "movies" ORDER BY title
22:38:03 web.1 | Rendered movies/index.html.erb within layouts/application (14.9ms)
A failed commit does sound like a great explanation. I'm not yet sure how to check whether the driver is set to commit or to see how/when a commit might have failed.
This is a very simple application, with no load balancing or complex configuration and most of the code was generated by the 'generate scaffold' command, but it's entirely possible that there's some constraint that's being violated somewhere before the db is ever hit. Perhaps there's a way to crank the Foreman (or Rails) log level up to 11? I also tried using thin instead and scoured the log files in the log/ folder and didn't find anything other than what's logged above.
This sounds a lot like a transaction issue, where you aren't COMMITting your transactions after you do work, so the changes are lost. If your SQLite driver defaults to COMMITting transactions that're closed without an explicit COMMIT or rollback, and your Pg driver defaults to ROLLBACK, you'd get the behaviour described. The same will happen if the SQLite defaults to autocomitting each statement by default, and the Pg driver driver defaults to opening a transaction.
This is one of the many good reasons to use the same local database for testing as you're going to deploy to when you want to go live.
If you were on a normal Pg instance I'd tell you to enable log_statement = 'all' in postgresql.conf, reload Pg, and watch the logs. You can't do that on Heroku, but you do have access to the Pg logs with heroku logs --ps postgres. Try running ALTER USER my_heroku_user SET log_statement = 'all';, re-testing, and examining the logs.
Alternately, install Pg locally.
Other less likely possibilities that come to mind:
You're using long-running SERIALIZABLE transactions for reads, so their snapshot never gets updated. Pretty unlikely.
Permissions on database objects are causing INSERTs, UPDATEs, etc to fail, and your app is ignoring the resulting errors. Again, unlikely.
You have DO INSTEAD rules that don't do what you expect, or BEFORE triggers that return NULL, thus silently turning operations into no-ops. Seems unlikely if you're testing with SQLite.
You're writing to a different DB than you're reading from. Not impossible in setups that're attempting to read from a cluster of hot standbys, etc.
Having issues upon deploying to heroku regarding tables constructed using find statements. They functioned perfectly when using a local server but not there up on heroku I get the 'were sorry, but something went wrong' error. I came across some other threads suggesting it may be an issue with case sensitivity in postgresql not that I know much about it but I tried making sure the capitalization was consistent throughout and it didnt seem to make a difference.
Heroku Logs
2012-08-14T00:31:30+00:00 app[web.1]: Processing by ApartmentsController#aptMenu as HTML
2012-08-14T00:31:30+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms
2012-08-14T00:31:30+00:00 app[web.1]:
2012-08-14T00:31:30+00:00 app[web.1]: LINE 1: SELECT "apartments".* FROM "apartments" WHERE (bed = 0)
2012-08-14T00:31:30+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::Error: ERROR: column "bed" does not exist
Controller
def aptMenu
#apartments = Apartment.all
#studio = Apartment.find(:all, :conditions => ["bed = 0"])
Schema
create_table "apartments", :force => true do |t|
t.integer "bed"
Im pretty confused with this seeing as according to everything I can see the 'bed' column does exist. Any help would be much appreciated.
This problem occurs because the Apartment table on production database is missing the column Bed. You need to migrate on production side.
heroku rake db:migrate
See if the new column comes up.
Make sure you restart your heroku as well.
heroku restart