daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Company < ApplicationRecord
  2.   has_many :describes, dependent: :destroy
  3.   has_many :descriptors, through: :describes, source: :metadatum
  4. end
  5.  
  6. class Metadatum < ApplicationRecord
  7.   has_many :describes, dependent: :destroy
  8.   has_many :descriptees, through: :describes, source: :company
  9.  
  10.   ...
  11. end
  12.  
  13. class Describe < ApplicationRecord
  14.   belongs_to :company
  15.   belongs_to :metadatum
  16. end
  17.  
  18. class CompaniesController < ApplicationController
  19.   ...
  20.  
  21.   def destroy
  22.     @company = Company.find(params[:id])
  23.     @company.destroy
  24.     redirect_to companies_url
  25.   end
  26.  
  27.   ...
  28. end
  29.  
  30. ActiveRecord::Schema.define(version: <some version #) do
  31.  
  32.   create_table "companies", force: :cascade do |t|
  33.     t.string   "name"
  34.     t.string   "description"
  35.     t.datetime "created_at",  null: false
  36.     t.datetime "updated_at",  null: false
  37.     t.index ["name"], name: "index_companies_on_name", unique: true
  38.   end
  39.  
  40.   create_table "describes", id: false, force: :cascade do |t|
  41.     t.integer  "company_id"
  42.     t.integer  "metadatum_id"
  43.     t.datetime "created_at",   null: false
  44.     t.datetime "updated_at",   null: false
  45.     t.index ["company_id"], name: "index_describes_on_company_id"
  46.     t.index ["metadatum_id"], name: "index_describes_on_metadatum_id"
  47.   end
  48.  
  49.   create_table "metadata", force: :cascade do |t|
  50.     t.string   "name"
  51.     t.string   "description"
  52.     t.datetime "created_at",  null: false
  53.     t.datetime "updated_at",  null: false
  54.     t.index ["name"], name: "index_metadata_on_name", unique: true
  55.   end
  56.  
  57. end
  58.  
  59. class CreateCompanies < ActiveRecord::Migration[5.0]
  60.   def change
  61.     create_table :companies do |t|
  62.       t.string :name
  63.       t.string :description
  64.  
  65.       t.timestamps
  66.     end
  67.     add_index :companies, :name, unique: true
  68.   end
  69. end
  70.  
  71. class CreateMetadata < ActiveRecord::Migration[5.0]
  72.   def change
  73.     create_table :metadata do |t|
  74.       t.string :name
  75.       t.string :description
  76.  
  77.       t.timestamps
  78.     end
  79.     add_index :metadata, :name, unique: true
  80.   end
  81. end
  82.  
  83. class CreateDescribes < ActiveRecord::Migration[5.0]
  84.   def change
  85.     create_table :describes, id: false do |t|
  86.       t.references :company, foreign_key: true
  87.       t.references :metadatum, foreign_key: true
  88.  
  89.       t.timestamps
  90.     end
  91.   end
  92. end
  93.    
  94. @company.destroy
  95.    
  96. undefined method `to_sym' for nil:NilClass Did you mean? to_s
  97.    
  98. def create
  99.   @company = Company.new(company_attributes)
  100.  
  101.   params[:metadata][:ids].each do |m|
  102.     if !m.empty?
  103.       @company.descriptors << Metadatum.find(m)
  104.     end
  105.   end
  106.  
  107.   if @company.save
  108.  
  109.   ...
  110. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top