I’m developing a blog site for practice. My problem is I can’t call data from one object to another related object.
Here are my model associations:
1 class Post < ActiveRecord::Base
2 belongs_to :user
3 end
1 class User < ActiveRecord::Base
2 has_many :posts
3 end
In the console:
user = User.find(1)
user.posts // Everything works! It shows me a list of posts related to the user.
user.post(1) //This doesn't work! Is it wrong?
I’ve been looking over active record query interface guide at rubyonrails.org and still can’t find anything in reference to this. Maybe I missed something?
Thanks
Do it this way: