1
I’m trying to make a relationship between two tables in Ruby, where I use the student and grades but when I go to localhost:3000/Students/1/Notes it causes me the error
my notes_controller.Rb:
class NotesController < ApplicationController
def index
@student = Note.find(params[:student_id])
@notes = @student.notes
end
end
Notes.Rb
class Note < ApplicationRecord
belongs_to :student end
student Rb.
class Student < ApplicationRecord
has_many :notes , dependent: :destroy
end
Any idea why he says the Notes method is undefined?
What is the Note method ? you are probably accessing it in a way that it does not allow to be called if it is' def self.Note 'you can access with Note.find() but if it is 'def Note' you call Note.new.find.();
– AnthraxisBR
I tried using Note.new.find(), but gave that the find method is undefined.
– Erick Ferreira
From what little I understand of Ruby, Note is a class, not a method, and you’re accessing it as if it were a method, you’re just saying in Notes that it belongs to the student (what’s not wrong too?, shouldn’t it be Student ?), and have a method to set Notes.Metodo.find(params[:student_id]), I think so will work, but what I can/know palpitate ends here.
– AnthraxisBR
Actually I had switched the balls. Replace Note.find() with Student.find and it worked. Thanks for the help
– Erick Ferreira