Agregar group_id a las notas

Estoy buscando construir una aplicación donde unuser puede iniciar sesión, crear ungroup y publicarnotes en el grupo.user debe poder invitar a otrosuser algroup si ya existen, y si no existen, envíeles una invitación para registrarse y colóquelos en esegroup

Actualmente hay unuser group ynotes modelo. Tengo dificultades para agregar ungroup_id alnotes así que esonotes pertenecer al grupo y el índice para elgroup solo muestranotes que esogroup_id.

db / migrate

class AddUserIdToNotes < ActiveRecord::Migration
  def change
    add_column :notes, :group_id, :integer
  end
end

modelos / note.rb

class Note < ActiveRecord::Base
  belongs_to :group
end

modelos / group.rb

class Group < ActiveRecord::Base
  has_many :notes
end

controllers / notes_controller.rb

class NotesController < ApplicationController
    before_action :find_note, only: [:show, :edit, :update, :destroy]

    def index
        @notes = Note.where(group_id: current_user).order("created_at DESC")
    end

    def new
        @note = current_user.notes.build
    end

    def create
        @note = current_user.notes.build(note_params)

        if @note.save
            redirect_to @note
        else
            render 'new'
        end
    end

    def edit
    end

    def update
        if @note.update(note_params)
            redirect_to @note
        else
            render 'edit'
        end
    end

    def destroy
        @note.destroy
            redirect_to notes_path
    end

    private

    def find_note
        @note = Note.find(params[:id])
    end

    def note_params
        params.require(:note).permit(:title, :content)
    end
end

Respuestas a la pregunta(1)

Su respuesta a la pregunta