Post.find returns an array of post instances. The instance method post_comments returns an array of comments instances.
The create method doesn't belong either to a particular comment instance, nor to Array.
You should be calling Post.create and adjusting your params as such.
Plus if you check your development.log, you'll likely see something like "create is not a method of Array". This log should be a key source of debugging.
Post.find only returns a single object if only one is found (i.e. when
finding by params[:id] as above).
post.post_comments is an association proxy that will return an array of
related PostComment objects *but*, you can also call methods such as
create on it as well. See the API docs for more information.
Post.find only returns a single object if only one is found (i.e. when
finding by params[:id] as above).
post.post_comments is an association proxy that will return an array of
related PostComment objects *but*, you can also call methods such as
create on it as well. See the API docs for more information.
I stand corrected. Thank you.
This is one area of the documentation (IMO) is weak . But consulting through irb, and .methods .instance_methods ljredpath is correct.
Thanks for the response. I follow you on the first part where you say
"Post.find only returns a single object if only one is found (i.e. when
finding by params[:id] as above).", but I lost you on the second part.
I will definitely check the API documentation, but I'm not sure where
to look. Can you explain the second part in a little more detail or
refer me to the proper area of the API docs?
Got it now!! I had a validates_presence_of in my model for a field that
I had deleted from the table. Anyone have any idea why rails doesn't
tell you when you make a dumb mistake like that??