public
Description: Ratings for your model.
Homepage: http://zachinglis.com
Clone URL: git://github.com/zachinglis/is_rateable.git
Search Repo:
Click here to lend your support to: is_rateable and make a donation at www.pledgie.com !
name age message
folder MIT-LICENSE Thu Jul 17 08:50:36 -0700 2008 initial commit [zachinglis]
folder README.textile Fri Jul 18 20:42:02 -0700 2008 Updating README [zachinglis]
folder Rakefile Thu Jul 17 08:50:36 -0700 2008 initial commit [zachinglis]
folder generators/ Fri Jul 18 15:08:57 -0700 2008 Finished and working [zachinglis]
folder init.rb Thu Jul 17 11:02:00 -0700 2008 Started work on the view helpers [zachinglis]
folder install.rb Thu Jul 17 08:50:36 -0700 2008 initial commit [zachinglis]
folder lib/ Mon Jul 21 06:58:22 -0700 2008 Making the rating local to that instance [zachinglis]
folder tasks/ Thu Jul 17 08:50:36 -0700 2008 initial commit [zachinglis]
folder test/ Thu Jul 17 08:50:36 -0700 2008 initial commit [zachinglis]
folder uninstall.rb Thu Jul 17 08:50:36 -0700 2008 initial commit [zachinglis]
README.textile

is_rateable

Currently star buttons are a put request, not a post request like they should be due to time constraints. Should be fixed in a future version.

Patches welcome! I do test my own stuff but until I find a nice and easy way to include rspec in plugins, they won’t come with the specs.

Usage

To install, type script/generate rateable

In your model.
    is_rateable :upto => 5 # it defaults :upto => 5
  
In your view.
    render_rating(@book, :interactive_stars)
    render_rating(@book) # If you want to also see 1/5 Stars
  

If a user rates more than twice, it will delete their older rating and put up a new rating.

Add a method to your books_controller like so:
    def rate
      @book = Book.find(params[:id])
      unless @book.add_rating(params[:rating].to_i, :ip => request.remote_ip)
        flash[:notice] = "You have already voted on this book" 
      end
      redirect_to @book
    end
  

Todo

  • Annotate methods

Credits

Copyright© 2008 Zach Inglis, released under the MIT license