![]() The Cancel button is shown on the left, by default. Here is how to change the path: Visual Effects: Īnd here is how to change each icon separately:Ĭhanging the Position of the Cancel Button You can customize each icon using its specific option, or just change the path to other icons with the same name. One of the most useful options in this helper is to customize the icons of the stars. To enable it, just use this option: Visual Effects: There is a useful option in which user can rate using half values, which is disabled by default. This is the default behavior, but if you want to disable half stars, use the half_show option: Visual Effects: Rating with More Precision Once there are several ratings, it is likely that the average score will have half stars and, thus, be half-highlighted. Now the stars will not be disabled after the user’s first rating. Set it to false as follows: Visual Effects: This option is disable afterrate, which is set to true by default. However, there is an option to let it remain enabled so the user can change the rating. The number of stars can be changed by simply using the option stars: Visual Effects: īy default, after the user provides a rating the stars are disabled. This feature can be disabled, as we will discover later. Step 5:** Explore the rating_for OptionsĪs you can see, the user can cancel the rating. The view uses the provided rating_for helper to show the rating for each dimension that was specified. ![]() Open up the “show” view of the movies, which you can find in app/views/movies/ Step 4: Using the Ratyrate Helper in Views This also adds the required association to the User model. For our MovieStore application, it is the User model, so add the following line to it: ratyrate_rater You also need to define the model that will do the actual rating. This line also creates the required associations. This adds some dimensions which the user can rate. Open the Movie model, or whatever model you want to add the starring capabilities to, and add the following line: ratyrate_rateable 'visual_effects', 'original_score', 'director', 'custome_design' In our case, however, you don’t need to run the Devise generators as the moviestore repository has done that already. This generator will create Rate and RatingCache models linked to your User model. $ rails g ratyrate user # => user is the model generated by devise The Devise generator and ratyrate generator then look like: $ rails g devise:install Suppose you have a Devise user model named User. To run the migration: $ rake db:migrate Example Run the migrations created with this generator, which create the required tables for the rating functionality. Output files: create app/assets/javascripts/Ĭreate app/assets/javascripts/ratyrate.js.erbĬreate app/controllers/rater_controller.rb This is necessary to bind the user and rating data. In the terminal run: $ rails g ratyrate UserĪs you can see, this command takes a single argument: the name of your existing Devise user model. Now you need to run the gem’s generator to copy the required assets and files (jQuery Raty plugin files, star icons, and JavaScript files) to their correct locations in your Rails application. If you don’t know how to do that, here is the commands: $ git clone cd moviestore I assume you have already cloned the moviestore repository and are inside its directory. To use the development gem add the following to your Gemfile: gem 'ratyrate', :github => 'wazery/ratyrate', :branch => 'development' Step 2: Preparing the Application You may want to watch the repository and use the development version of Ratyrate because I am adding new features all the time. To install this Ruby gem simply include it in your Gemfile like so: gem 'ratyrate' Ratyrate has some awesome, new features, so you are welcome to star it :) Step 1: Installation of Ratyrate gem I forked it from a gem called Letsrate because of Letsrate’s inactivity. It also adds some helpers along the style of IMDB rating. ![]() Ratyrate is a Ruby gem that wraps the functionality of the Raty jQuery plugin.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |