I am building an application that will have a model that belongs_to another model most of the time, but in some other instances it will just need to be standalone and not have parents.
Just an example:
class Book < ActiveRecord::Base
has_many :pieces_of_paper
end
class PieceOfPaper < ActiveRecord::Base
belongs_to :books
end
But sometimes I will need to save a piece of paper without it belonging to a book
What would be the best/proper way to code for this?
I have looked around for an example of this and couldn’t find anything and maybe that’s just it, I could just be over thinking this and it’s very simple. I’ll be thankful for any help anyone can provide, thanks.
Yes, it’s very simple and I think you are “over thinking” it.
You can either test it in “rails console” or “unit test/rspec” environment.
e.g. rspec: