I planned everything carefully and tested locally, but after deploying may have created many useless records that have crashed the app on heroku.
My aim is to consolidate many models into one Topic model, so I used the below script in Heroku console (though should have tested one record at first):
> Question.find_each do |q|
* @qt=q.title
> @qd=q.description
> @q="Question"
> @ca=q.created_at
> @ui=q.user.id
> @uvt=q.user_votes_total
> Topic.create!({:title => @qt, :description => [@qd], :kind => @q, :created_at=>@ca, :user_id=>@ui, :user_votes_total=>@uvt })
> end
Heroku returns this:
Question Load (1.8ms) SELECT "questions".* FROM "questions" WHERE ("questions"."id" >= 0) ORDER BY "questions"."id" ASC LIMIT 1000
User Load (6.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3331 ORDER BY users.created_at DESC LIMIT 1
And, this DOH!:
WARNING: Can't mass-assign protected attributes: title, description, kind, created_at, user_id, user_votes_total
My topic model looks like this:
class Topic < ActiveRecord::Base
attr_accessible :description, :title, :kind, :user_id, :tag_list,
:subject, :image_attributes, :tags_attributes, :created_at,
:user_votes_total
validates :title, :presence => true,
:length => { :minimum => 5 }
validates :description, :presence => true
validates :kind, :presence => true
belongs_to :user
has_many :adds
default_scope order: 'topics.created_at DESC'
votable_by :users
acts_as_taggable
has_one :image, :as => :parent, :dependent => :destroy
accepts_nested_attributes_for :image, :allow_destroy => true
after_create do
self.create_image unless image
end
has_many :comments, :as => :commentable, :dependent => :destroy
include PgSearch
pg_search_scope :search, against: [:title, :description, :kind],
using: {tsearch: {dictionary: "english"}}
end
I have searched for relevant information, but can’t figure out why Heroku is not playing along. Has anyone encountered this issue?
I was able to overcome the issue by running:
https://devcenter.heroku.com/articles/ps