ruby on rails - Can't write unknown attribute using rails_admin -


im' using rails_admin save project has category within. didn't define project_id , category_id because thought should created rails. problem got using method def category_id=(id) defined in project model (see below). error is:

can't write unknown attribute `project_id` 

my models are:

category

class category < activerecord::base   belongs_to :project, :inverse_of => :category  end 

project

class project < activerecord::base   has_one :category, :dependent => :destroy, :inverse_of => :project    def category_id     self.category.try :id   end   def category_id=(id)     self.category = category.find_by_id(id)   end  end 

my schema:

create_table "categories", force: :cascade |t|     t.string   "title"     t.datetime "created_at", null: false     t.datetime "updated_at", null: false   end    create_table "projects", force: :cascade |t|     t.string   "title"     t.text     "text"     t.string   "url"     t.string   "key_feature"     t.string   "image_1"     t.string   "image_2"     t.string   "image_3"     t.datetime "created_at",  null: false     t.datetime "updated_at",  null: false   end 

how connect projects categories?

base on schema projects table has no category_id.

neither category table has project_id

i add category_id projects table.

rails g migration add_category_id_to_projects category_id:integer  rake db:migrate 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -