リビジョン 96155a96
| app/models/glossary_category.rb | ||
|---|---|---|
|
class GlossaryCategory < ActiveRecord::Base
|
||
|
has_many :terms, class_name: 'GlossaryTerm', foreign_key: 'category_id'
|
||
|
end
|
||
| app/models/glossary_term.rb | ||
|---|---|---|
|
class GlossaryTerm < ActiveRecord::Base
|
||
|
belongs_to :category, class_name: 'GlossaryCategory', foreign_key: 'category_id'
|
||
|
end
|
||
| db/migrate/002_create_glossary_categories.rb | ||
|---|---|---|
|
class CreateGlossaryCategories < ActiveRecord::Migration[5.1]
|
||
|
def change
|
||
|
create_table :glossary_categories do |t|
|
||
|
t.string :name
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| db/migrate/003_add_category_to_glossary_terms.rb | ||
|---|---|---|
|
class AddCategoryToGlossaryTerms < ActiveRecord::Migration[5.1]
|
||
|
def change
|
||
|
add_reference :glossary_terms, :category, foreign_key: true
|
||
|
end
|
||
|
end
|
||
| test/unit/glossary_category_test.rb | ||
|---|---|---|
|
require File.expand_path('../../test_helper', __FILE__)
|
||
|
|
||
|
class GlossaryCategoryTest < ActiveSupport::TestCase
|
||
|
|
||
|
# Replace this with your real tests.
|
||
|
def test_truth
|
||
|
assert true
|
||
|
end
|
||
|
end
|
||
[phase-5]added category model and modified term model