Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Company < ApplicationRecord
- has_many :describes, dependent: :destroy
- has_many :descriptors, through: :describes, source: :metadatum
- end
- class Metadatum < ApplicationRecord
- has_many :describes, dependent: :destroy
- has_many :descriptees, through: :describes, source: :company
- ...
- end
- class Describe < ApplicationRecord
- belongs_to :company
- belongs_to :metadatum
- end
- class CompaniesController < ApplicationController
- ...
- def destroy
- @company = Company.find(params[:id])
- @company.destroy
- redirect_to companies_url
- end
- ...
- end
- ActiveRecord::Schema.define(version: <some version #) do
- create_table "companies", force: :cascade do |t|
- t.string "name"
- t.string "description"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["name"], name: "index_companies_on_name", unique: true
- end
- create_table "describes", id: false, force: :cascade do |t|
- t.integer "company_id"
- t.integer "metadatum_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["company_id"], name: "index_describes_on_company_id"
- t.index ["metadatum_id"], name: "index_describes_on_metadatum_id"
- end
- create_table "metadata", force: :cascade do |t|
- t.string "name"
- t.string "description"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["name"], name: "index_metadata_on_name", unique: true
- end
- end
- class CreateCompanies < ActiveRecord::Migration[5.0]
- def change
- create_table :companies do |t|
- t.string :name
- t.string :description
- t.timestamps
- end
- add_index :companies, :name, unique: true
- end
- end
- class CreateMetadata < ActiveRecord::Migration[5.0]
- def change
- create_table :metadata do |t|
- t.string :name
- t.string :description
- t.timestamps
- end
- add_index :metadata, :name, unique: true
- end
- end
- class CreateDescribes < ActiveRecord::Migration[5.0]
- def change
- create_table :describes, id: false do |t|
- t.references :company, foreign_key: true
- t.references :metadatum, foreign_key: true
- t.timestamps
- end
- end
- end
- @company.destroy
- undefined method `to_sym' for nil:NilClass Did you mean? to_s
- def create
- @company = Company.new(company_attributes)
- params[:metadata][:ids].each do |m|
- if !m.empty?
- @company.descriptors << Metadatum.find(m)
- end
- end
- if @company.save
- ...
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement