Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 53 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ A Ruby Gem that wrap the functionality of [jQuery Raty](https://github.com/wbote
[![Support jQuery Raty](http://img.shields.io/gittip/wbotelhos.svg)](https://www.gittip.com/wazery "Git Tip")
[![Stories in Ready](https://badge.waffle.io/wazery/ratyrate.png?label=ready&title=Ready)](https://waffle.io/wazery/ratyrate)
[![Code Triagers Badge](https://www.codetriage.com/wazery/ratyrate/badges/users.svg)](https://www.codetriage.com/wazery/ratyrate)
[![Backers on Open Collective](https://opencollective.com/ratyrate/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/ratyrate/sponsors/badge.svg)](#sponsors)
[![Backers on Open Collective](https://opencollective.com/ratyrate/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/ratyrate/sponsors/badge.svg)](#sponsors)

## Repository

Expand All @@ -20,25 +20,25 @@ This is a fork against the repository [muratguzel/letsrate](https://github.com/m
## Changelog from the main repository

1. Exposed a lot of jQuery Raty plugin [features](http://wbotelhos.com/raty)
1. Added cancel button that can be customized and inserted to left or right
2. Added the ability to set custom star images for on, half or off state
3. Added the ability to set a custom path for the images
4. Added the ability to enable/disable half stars
5. Added the ability to turn on/off half star
2. Their is a new option now to disable or enable the rating after the first rate
3. Added a star style to show just the score of the dimension, but this star is not editable
4. Added an overall average star just like IMDB style
5. Created a Heroku app to illustrate this Gem's purpose and features (MovieStore)
6. [Wrote a complete tutorial on SitePoint that illustrates how to use this gem](http://www.sitepoint.com/ratyrate-add-rating-rails-app/)
3. Nothing else
4. :wq
1. Added cancel button that can be customized and inserted to left or right
1. Added the ability to set custom star images for on, half or off state
1. Added the ability to set a custom path for the images
1. Added the ability to enable/disable half stars
1. Added the ability to turn on/off half star
1. Their is a new option now to disable or enable the rating after the first rate
1. Added a star style to show just the score of the dimension, but this star is not editable
1. Added an overall average star just like IMDB style
1. Created a Heroku app to illustrate this Gem's purpose and features (MovieStore)
1. [Wrote a complete tutorial on SitePoint that illustrates how to use this gem](http://www.sitepoint.com/ratyrate-add-rating-rails-app/)
1. Nothing else
1. :wq

## TODO

1. Write RSpec tests for this Gem
3. Add option to show the number of users who gave rates
4. Add a share helper to Facebook, Twitter
5. Force refresh after rating when ***disable_after_rate*** and ***imdb_avg*** options is set to true.
2. Add option to show the number of users who gave rates
3. Add a share helper to Facebook, Twitter
4. Force refresh after rating when **_disable_after_rate_** and **_imdb_avg_** options is set to true.

## Detailed view of the new features

Expand Down Expand Up @@ -79,17 +79,19 @@ rails g ratyrate user # => user is the model generated by devise
```

This generator will create Rate and RatingCache models,
db/migrations,
db/migrations,
and link to your user model.

### Database Migration

Run the migrations:

```
rake db:migrate
```

### Javascript include

```
//= require jquery.raty
//= require ratyrate
Expand Down Expand Up @@ -135,61 +137,86 @@ Price : <%= rating_for @car, 'price' %>
### Available Options

1- If you need to change the star number, you should use star option like below.

```erb
Speed : <%= rating_for @car, 'speed', star: 10 %>
Engine : <%= rating_for @car, 'engine', star: 7 %>
Price : <%= rating_for @car, 'price' %>
```
2- If you want to disable/enable the rating after user's first rate use the new option *disable_after_rate*

2- If you want to disable/enable the rating after user's first rate use the new option _disable_after_rate_

```erb
Speed : <%= rating_for @car, 'speed', disable_after_rate: true %>
```
To enable changes after first user rate set ```disable_after_rate``` to false

3- To enable half stars use the option *enable_half*
To enable changes after first user rate set `disable_after_rate` to false

3- To enable half stars use the option _enable_half_

```erb
Speed : <%= rating_for @car, 'speed', enable_half: true %>
```
4- To show or hide the half stars use *half_show*

4- To show or hide the half stars use _half_show_

```erb
Speed : <%= rating_for @car, 'speed', half_show: true %>
```

5- To change the path in which the star images (star-on.png, star-off.png, star-half.png, ..etc) are located use

```erb
Speed : <%= rating_for @car, 'speed', star_path: true %>
```

To just change one of the star images choose from these options (star_on, star_off, star_half)

6- To add the cancel button to the left, or right of the stars use **(default is false)**

```erb
Speed : <%= rating_for @car, 'speed', cancel: true %>
```

7- To change the place of the cancel button (left, or right) use **(default is left)**

```erb
Speed : <%= rating_for @car, 'speed', cancel_place: left %>
```

8- To change the hint on the cancel button use **(default is "Cancel current rating!" )**

```erb
Speed : <%= rating_for @car, 'speed', cancel_hint: 'Cancel this rating!' %>
```

9- To change the image of the cancel on button use

```erb
Speed : <%= rating_for @car, 'speed', cancel_on: 'cancel-on2.png' %>
```

10- To change the image of the cancel off use

```erb
Speed : <%= rating_for @car, 'speed', cancel_off: 'cancel-off2.png' %>
```

11- To hide average for user **(default is false)**

```erb
Speed : <%= rating_for @car, 'speed', hide_average: true %>
```

### Other Helpers

You can use the *rating_for_user* helper method to show the star rating for the user.
You can use the _rating_for_user_ helper method to show the star rating for the user.

```erb
Speed : <%= rating_for_user @car, current_user, 'speed', star: 10 %>
```

And you can use the *imdb_style_rating_for* to show a similar to IMDB rating style.
And you can use the _imdb_style_rating_for_ to show a similar to IMDB rating style.

```erb
Speed : <%= imdb_style_rating_for @car, current_user %>
Expand All @@ -208,21 +235,20 @@ Ratyrate attempts to follow semantic versioning in the format of `x.y.z`, where:
In other words: `Major.Minor.Patch`.

## Feedback

If you find bugs please open a ticket at [https://github.com/wazery/ratyrate/issues](https://github.com/wazery/ratyrate/issues)

## Contributors

This project exists thanks to all the people who contribute.
This project exists thanks to all the people who contribute.
<a href="https://github.com/wazery/ratyrate/graphs/contributors"><img src="https://opencollective.com/ratyrate/contributors.svg?width=890&button=false" /></a>


## Backers

Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/ratyrate#backer)]

<a href="https://opencollective.com/ratyrate#backers" target="_blank"><img src="https://opencollective.com/ratyrate/backers.svg?width=890"></a>


## Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/ratyrate#sponsor)]
Expand Down
3 changes: 2 additions & 1 deletion lib/ratyrate/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def rating_for(rateable_obj, dimension=nil, options={})
targetFormat = options[:targetFormat] || '{score}'
targetScore = options[:targetScore] || ''
readOnly = options[:readonly] || false
hide_average = options[:hide_average] || false

disable_after_rate = options[:disable_after_rate] && true
disable_after_rate = true if disable_after_rate == nil
Expand All @@ -44,7 +45,7 @@ def rating_for(rateable_obj, dimension=nil, options={})
content_tag :p, avg, :style => "position:relative;font-size:.8rem;text-align:center;line-height:60px;"
end
else
content_tag :div, '', "data-dimension" => dimension, :class => "star", "data-rating" => avg,
content_tag :div, '', "data-dimension" => dimension, :class => "star", "data-rating" => hide_average == true ? 0 : avg,
"data-id" => rateable_obj.id, "data-classname" => rateable_obj.class.name == rateable_obj.class.base_class.name ? rateable_obj.class.name : rateable_obj.class.base_class.name,
"data-disable-after-rate" => disable_after_rate,
"data-readonly" => readOnly,
Expand Down