Skip to content

joebva/rate_fu

Repository files navigation

RateFu
==

Thanks goes to vote_fu, rails_widgets – spiffy_corners and stars-ratings css.

Install
==

Run the following command:


./script/plugin install git://github.com/joebva/rate_fu.git

Create a new rails migration using the generator:


./script/generate rate_fu RateableModel

This will create a migration file (‘ratings’ table) and a directory /app/views/ratings with a partial and a .rjs file. It will also move stars.gif to public/images.

Add this to all the models you want to be rate: (articles, photos, images)


acts_as_rateable

Add this to all the models you want to rate things: (users, accounts, employees)


acts_as_rater

Add this to the show view of each model you set as ‘acts_as_rateable’


<% rating_stars :generate_css => true >

<= render :partial => “ratings/rating”, :locals => { :rateable => @rateable } %>

The rating_stars method inserts inline css. This can be omitted if you move the styles into your css file.

Add this to your controller show action for each rateable model:


def show
@article = Article.find(params[:id])
@rateable = @article
# TODO for testing find the first user
@current_user ? @current_user = User.find(params[:user_id]) : @current_user = User.find(:first)
end

Make sure you include javascript in the head:


<%= javascript_include_tag :defaults %>

Add this to your routes file (config/routes.rb)


map.connect ‘ratings/rate/:id’, :controller => ‘ratings’, :action => ‘rate’, :method => ‘post’

Make sure you update ratings_controller.rb to reflect the current user. (vendor/plugins/rate_fu/lib/app/controllers/ratings_controller.rb)

Example Application
===

rails rate_test
cd rate_test
script/generate scaffold User name:string
script/generate scaffold Article title:string
script/plugin install git://github.com/joebva/rate_fu.git
script/generate rate_fu RateableModel
rake db:migrate
-add acts_as_rateable (app/models/article.rb)
-add acts_as_rater (app/models/user.rb)
-update rateable show views in controller (app/controllers/articles_controller.rb)
-add partial to view (app/views/articles/show.html.erb)
script/generate controller Ratings
-add rate method to RatingsController (app/controllers/ratings_controller.rb)
-add ‘javascript_include_tag :defaults’ to layout (app/views/layouts/articles.html.erb)
-add “map.connect ‘ratings/rate/:id’, :controller => ‘ratings’, :action => ‘rate’, :method => ‘post’” to your routes (app/config/routes.rb)
script/server
-add user (localhost:3000/users)
-add article (localhost:3000/articles)
-rate article
Done!

Copyright © 2009 [Joseph Belcher], released under the MIT license

About

Rating management system for Ruby on Rails - Star rating plugin with CSS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages