When a list of posts are generated, I want a logged in user to be able to click a star to favorite that post. Any suggestions on how to do this over ajax? I guess I would use a many_to_many relationship for this, but just not sure about posting over ajax in rails.
Share
First: your associations could be more explicit with a join table, like UserFavourites(user_id, post_id), and do:
Then in your views you could create a favourites link (the star image) and let’s say that that link had an ID of
favourite. Then you could use jQuery (or whatever) and do:This will require some controller action in Users called add_favourite, and you can have it return some HTML or return nothing and just add the favourite to the user.