ruby on rails - renamed a table and am getting errors -
i named table types
, realized reserved word, renamed 'category`.
now when try activerecord query, error:
pg::undefinedtable: error: relation "categories" not exist line 5: a.attrelid = '"categories"'::regclass ^ : select a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod pg_attribute left join pg_attrdef d on a.attrelid = d.adrelid , a.attnum = d.adnum a.attrelid = '"categories"'::regclass , a.attnum > 0 , not a.attisdropped order a.attnum
i have gone though code , changed relation names, model, controller, etc...but don't know error coming from. or means. here category.rb:
class category < activerecord::base has_many :projects end
here categories_controller.rb: class categoriescontroller < applicationcontroller
def create @category = category.new(category_params) if @category.save redirect_to root_path else redirect_to({:controller => 'application', :action => 'home'}, :notice => 'account not created! fishy.') end end end
and here trying inside user model (because want code read along lines of current_user.contributions_by_category
def contributions_by_category(array) category = {} array.each |subarray| name = category.find(subarray[1].category_id).project_category; category[name] = 0 unless category.include?(name) category[name] += subarray[0] unless subarray[0] == nil end category end
also, inside of project model have:
class project < activerecord::base belongs_to :user, :foreign_key => 'user_id' belongs_to :category, :foreign_key => 'category_id' #should change has 1 association has_many :users has_many :payments has_many :updates has_many :comments has_one :imapct .... end
before switched name, able make query work in rails console rendering screen, relation exists, did change name.
any appreciated!
update:
here table data rails console:
list of relations schema | name | type | owner --------+-------------------+-------+------------- public | categories | table | seinnaidess public | comments | table | seinnaidess public | entrepreneurs | table | seinnaidess public | impacts | table | seinnaidess public | payments | table | seinnaidess public | projects | table | seinnaidess public | schema_migrations | table | seinnaidess public | update_comments | table | seinnaidess public | updates | table | seinnaidess public | users | table | seinnaidess
and here schema:
activerecord::schema.define(version: 20150930040619) # these extensions must enabled in order support database enable_extension "plpgsql" create_table "categories", force: :cascade |t| t.string "category_type" end create_table "comments", force: :cascade |t| t.text "content" t.integer "user_id" t.integer "project_id" t.datetime "created_at" t.datetime "updated_at" end create_table "entrepreneurs", force: :cascade |t| t.string "first_name" t.string "last_name" t.string "password_digest" t.text "about" t.string "location" t.integer "age" t.float "repayment_rate" t.integer "project_id" t.datetime "created_at" t.datetime "updated_at" end create_table "impacts", force: :cascade |t| t.integer "ppl_hired", default: 0 t.integer "ppl_schooled", default: 0 t.integer "improved_housing", default: 0 t.integer "improved_nourishment", default: 0 t.integer "improved_medical", default: 0 t.integer "community_resource", default: 0 t.integer "project_id" t.datetime "created_at" t.datetime "updated_at" end create_table "payments", force: :cascade |t| t.string "first_name" t.string "last_name" t.float "amount" t.integer "cc_num" t.integer "exp_month" t.integer "exp_year" t.integer "cvs" t.integer "user_id" t.integer "project_id" t.datetime "created_at" t.datetime "updated_at" t.text "comments" end create_table "projects", force: :cascade |t| t.string "name" t.text "url" t.text "description" t.float "money_needed", default: 0.0 t.float "money_raised", default: 0.0 t.float "interest_offered", default: 0.0 t.datetime "end_date" t.integer "category_id" t.integer "user_id" t.datetime "created_at" t.datetime "updated_at" end create_table "update_comments", force: :cascade |t| end create_table "updates", force: :cascade |t| t.text "content" t.string "url" t.integer "project_id" t.string "date" end create_table "users", force: :cascade |t| t.string "first_name" t.string "last_name" t.string "user_name" t.string "password_digest" t.string "impact" t.text "pic_url" t.text "quote" t.integer "payment_id" t.integer "project_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "admin" end
Comments
Post a Comment