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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -