User Favorites System in Rails -
first sorry english;
for learning purpose have create blog authentication ( using devise), want user able favorited other users posts when visit favorited posts pages see posts saved. appreciate if can give me tutorial link or guide me
for adding feature enable users favorite other users post need create association user , post models might have created
class user < activerecord::base has_many :posts has_many :favorites, :dependent => :destroy has_many :favorite_posts, :through => :favorites, :source => :post end class post < activerecord::base belongs_to :user has_many :favorites, :dependent => :destroy has_many :favorited, :through => :favorites, :source => :user end class favorite < activerecord::base belongs_to :user belongs_to :post end you can use these models add necessary features , create posts , favorites using associations.
for example: myname = user.create (:name => 'user333') yourname = user.create (:name => 'user444')
mypost = myname.posts.create (:head => 'hello', :body => 'post content') yourname.favorites.create (:post => mypost)
this code give favorite posts of user444 if myname.favorite_posts
there tutorials on creating bookmarks, following other users , creating favorites on web http://doblock.com/articles/creating-an-extensible-user-favorites-system-in-rails http://12devs.co.uk/articles/writing-a-web-application-with-ruby-on-rails/
good luck !!
Comments
Post a Comment