Add tag association to learning goals

This commit is contained in:
Trevor Vallender 2024-01-06 11:10:56 +00:00
parent 484d10385a
commit 6b43cfa813
6 changed files with 19 additions and 1 deletions

View File

@ -56,6 +56,7 @@ class LearningGoalsController < ApplicationController
:retrospective, :retrospective,
:completed, :completed,
:user, :user,
tag_ids: [],
) )
end end

View File

@ -5,4 +5,7 @@ class LearningGoal < ApplicationRecord
has_rich_text :retrospective has_rich_text :retrospective
validates :title, presence: true validates :title, presence: true
has_and_belongs_to_many :tags
accepts_nested_attributes_for :tags
end end

View File

@ -4,6 +4,7 @@ class Tag < ApplicationRecord
validates :name, presence: true validates :name, presence: true
has_many :microposts_tags has_many :microposts_tags
has_many :microposts, through: :microposts_tags has_many :microposts, through: :microposts_tags
has_and_belongs_to_many :learning_goals
def to_param def to_param
name name

View File

@ -16,6 +16,9 @@
<%= f.label :completed %> <%= f.label :completed %>
<%= f.check_box :completed %> <%= f.check_box :completed %>
<%= f.label :microposts_tag %>
<%= f.collection_check_boxes :tag_ids, Tag.all, :id, :name %>
<%= f.submit button_text %> <%= f.submit button_text %>
<% end %> <% end %>

View File

@ -0,0 +1,5 @@
class LearningGoalTagAssociation < ActiveRecord::Migration[7.1]
def change
create_join_table :learning_goals, :tags
end
end

7
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_01_06_093517) do ActiveRecord::Schema[7.1].define(version: 2024_01_06_103226) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -108,6 +108,11 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_06_093517) do
t.index ["user_id"], name: "index_learning_goals_on_user_id" t.index ["user_id"], name: "index_learning_goals_on_user_id"
end end
create_table "learning_goals_tags", id: false, force: :cascade do |t|
t.bigint "learning_goal_id", null: false
t.bigint "tag_id", null: false
end
create_table "microposts", force: :cascade do |t| create_table "microposts", force: :cascade do |t|
t.bigint "user_id", null: false t.bigint "user_id", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false