ruby - rails attaching database entry to logged in user -
i'm new rails , done setting login system. however, want able make new blog post , attach account when logged in. how can attach post user_id list previous posts?
define model posts ( should have column name user_id )
model post < activerecord::base belongs_to :user end
in user model
model user < activerecord::base has_many :posts end
with above defined associations user_id foriegn key user model can posts user below
user.find(id).posts
Comments
Post a Comment