Skip to content

An updated version of acts as favorite Rails plugin, working on Rails versions 2.2.1 and higher.

License

Notifications You must be signed in to change notification settings

juafrlo/acts-as-favorite-updated

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Acts As Favorite
=================

   This is an update made by Juan de Frías of 'act_as_favorite' plugin made by Josh Martin, in order to make it work on Rails versions 2.2.1 and higher.

   This plugin provides a simple way to track users favorites within the system using
ActiveRecord models. 

== Requirements
  As we are not generating anything and there is no config, it is assumed in this version
  that your user class is named "User", and you dont have an existing "Favorite" class.

== Installation and Configuration

1) Install as a plugin using script/plugin.
2) Generate the Favorite model, migrations, and tests with ./script/generate favorite_model Favorite
3) rake migrate to create the required tables
4) add <tt>acts_as_favorite_user</tt> to your User model
5) add <tt>acts_as_favorite</tt> to any models which you want to provide to users for favorites.

== How to use it

  In the following examples, considerar there is a User model and
  a Restaurant model, which acts_as_favorite, so a user can have many favorite
  restaurants.
  Obviously, as long as a model is set to acts_as_favorite, it can use all the next methods,
  changing 'restaurant' by 'model_name' 

- To add a favorite to a user:
  current_user.has_favorite(Restaurant.find(2))  

- To test favorites (returns true/false):  
  current_user.has_favorite?(Restaurant.find(2)) 
  current_user.has_favorite_restaurants?  

- To find favorites:
  current_user.all_favorites  (all favorite referenced objects, like restaurants, etc)
  current_user.favorite_restaurants  (metaprogramming references Restaurant entries only)
  Restaurant.find(2).favoriting_users (returns users which have this restaurant set as a favorite)

== License
MIT License applies.

== Authors
  Juan de Frías
  Original version by Josh Martin (code at http://github.com/joergbattermann/acts_as_favorite/)

About

An updated version of acts as favorite Rails plugin, working on Rails versions 2.2.1 and higher.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages