Skip to content
This repository
Browse code

Merge pull request #3 from styx/master

Some updates
  • Loading branch information...
commit b5680d0d7fd1f94b75c25ed389e7a965ddb40699 2 parents 025a8b3 + 0ba3d79
Murat GUZEL authored
BIN  .DS_Store
Binary file not shown
130 README.md
Source Rendered
... ... @@ -1,9 +1,10 @@
1   -# Letsrate Rating Gem
  1 +# Letsrate Rating Gem
2 2
3 3 Provides the best way to add rating capabilites to your Rails application with jQuery Raty plugin.
4 4
5 5 [![Build Status](https://secure.travis-ci.org/muratguzel/letsrate.png)](http://travis-ci.org/muratguzel/letsrate)
6 6 [![Dependency Status](https://gemnasium.com/muratguzel/letsrate.png)](https://gemnasium.com/muratguzel/letsrate)
  7 +[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/muratguzel/letsrate)
7 8
8 9 ## Repository
9 10
@@ -15,85 +16,100 @@ Find it at [github.com/muratguzel/letsrate](https://github.com/muratguzel/letsra
15 16
16 17 Add the letsrate gem into your Gemfile
17 18
18   - gem 'letsrate'
19   -
  19 +```ruby
  20 +gem 'letsrate'
  21 +```
  22 +
20 23 ### Generate
21 24
22   - rails g letsrate User
  25 +```
  26 +rails g letsrate User
  27 +```
23 28
24 29 The generator takes one argument which is the name of your existing devise user model UserModelName. This is necessary to bind the user and rating datas.
25 30 Also the generator copies necessary files (jquery raty plugin files, star icons and javascripts)
26 31
27   -Example:
  32 +Example:
28 33
29 34 Suppose you will have a devise user model which name is User. The devise generator and letsrate generator should be like below
30 35
31   - rails g devise:install
32   - rails g devise user
  36 +```
  37 +rails g devise:install
  38 +rails g devise user
  39 +
  40 +rails g letsrate user # => user is the model generated by devise
  41 +```
33 42
34   - rails g letsrate user # => user is the model generated by devise
35   -
36   -This generator will create Rate and RatingCache models and link to your user model.
  43 +This generator will create Rate and RatingCache models and link to your user model.
37 44
38 45 ### Prepare
39 46
40   -I suppose you have a car model
  47 +I suppose you have a car model
41 48
42   - rails g model car name:string
  49 +```
  50 +rails g model car name:string
  51 +```
43 52
44 53 You should add the letsrate_rateable function with its dimensions option. You can add multiple dimensions.
45 54
46   - class Car < ActiveRecord::Base
47   - letsrate_rateable "speed", "engine", "price"
48   - end
49   -
50   -Then you need to add a call letsrate_rater in the user model.
51   -
52   - class User < ActiveRecord::Base
53   - letsrate_rater
54   - end
55   -
56   -
  55 +```ruby
  56 +class Car < ActiveRecord::Base
  57 + letsrate_rateable "speed", "engine", "price"
  58 +end
  59 +```
  60 +
  61 +Then you need to add a call letsrate_rater in the user model.
  62 +
  63 +```ruby
  64 +class User < ActiveRecord::Base
  65 + letsrate_rater
  66 +end
  67 +```
  68 +
57 69 ### Using
58 70
59   -There is a helper method which name is rating_for to add the star links. By default rating_for will display the average rating and accept the
60   -new rating value from authenticated user.
  71 +There is a helper method which name is rating_for to add the star links. By default rating_for will display the average rating and accept the
  72 +new rating value from authenticated user.
61 73
62   - #show.html.erb -> /cars/1
63   -
64   - Speed : <%= rating_for @car, "speed" %>
65   - Engine : <%= rating_for @car, "engine" %>
66   - Price : <%= rating_for @car, "price" %>
  74 +```erb
  75 +<%# show.html.erb -> /cars/1 %>
  76 +
  77 +Speed : <%= rating_for @car, "speed" %>
  78 +Engine : <%= rating_for @car, "engine" %>
  79 +Price : <%= rating_for @car, "price" %>
  80 +```
67 81
68 82 If you need to change the star number, you should use star option like below.
69   -
70   - Speed : <%= rating_for @car, "speed", :star => 10 %>
71   - Speed : <%= rating_for @car, "engine", :star => 7 %>
72   - Speed : <%= rating_for @car, "price" %>
73   -
74   -### Important
75   -
76   -By default rating_for tries to call devise current_user method as the rater instance in the rater_controller.rb file. You can change the current_user method
  83 +
  84 +```erb
  85 +Speed : <%= rating_for @car, "speed", :star => 10 %>
  86 +Speed : <%= rating_for @car, "engine", :star => 7 %>
  87 +Speed : <%= rating_for @car, "price" %>
  88 +```
  89 +
  90 +### Important
  91 +
  92 +By default rating_for tries to call devise current_user method as the rater instance in the rater_controller.rb file. You can change the current_user method
77 93 as you will.
78 94
79   - #rater_controller.rb
80   -
81   - def create
82   - if current_user.present?
83   - obj = eval "#{params[:klass]}.find(#{params[:id]})"
84   - if params[:dimension].present?
85   - obj.rate params[:score].to_i, current_user.id, "#{params[:dimension]}"
86   - else
87   - obj.rate params[:score].to_i, current_user.id
88   - end
89   -
90   - render :json => true
91   - else
92   - render :json => false
93   - end
94   - end
95   -
  95 +```ruby
  96 +#rater_controller.rb
  97 +
  98 +def create
  99 + if current_user.present?
  100 + obj = eval "#{params[:klass]}.find(#{params[:id]})"
  101 + if params[:dimension].present?
  102 + obj.rate params[:score].to_i, current_user.id, "#{params[:dimension]}"
  103 + else
  104 + obj.rate params[:score].to_i, current_user.id
  105 + end
  106 +
  107 + render :json => true
  108 + else
  109 + render :json => false
  110 + end
  111 +end
  112 +```
  113 +
96 114 ## Feedback
97 115 If you find bugs please open a ticket at [https://github.com/muratguzel/letsrate/issues](https://github.com/muratguzel/letsrate/issues)
98   -
99   -
BIN  lib/.DS_Store
Binary file not shown

0 comments on commit b5680d0

Please sign in to comment.
Something went wrong with that request. Please try again.