Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Rating Gem in Ruby on Rails

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 941
    Comment on it

    How to setup a rating feature in rails application.

     

    The best and simple way of doing so is by using RAILS GEM ratyrate by following simple steps.

     

    Step 1: Include GEM in your gem file

    gem 'ratyrate'

     

    Step 2:  Generate rating in respect of user by

    $ rails g ratyrate User

     

    Step 3: (Optional) Using with device

    $ rails g devise:install
    $ rails g devise user
    $ rails g ratyrate user # => user is the model generated by devise

     

    Step 4: Adding the ratyrate Associations

    Open the Movie model, or whatever MODEL you want to add the starring to, and paste the following code:

    ratyrate_rateable 'visual_effects', 'original_score', 'director', 'custome_design'

     

    Step 5: You also need to define the model which will provide the actual rating. For our MovieStore application, it is the User model, so add the following code to it:

    ratyrate_rater
    
    

     

     

    Step 6: Migrate the database

    $ rake db:migrate

     

    Step 7: Use it in the view level by the following code and remove whichever field is not needed as per your requirements:

    <div class="row">
      <div class="small-2 large-2 columns">
        <%= imdb_style_rating_for @movie, current_user%>
      </div>
      <br>
      <div class="small-2 large-4 columns">
        <% if current_user %>
          Visual Effects: <%= rating_for @movie, "visual_effects" %>
          <br>
          Original Score: <%= rating_for @movie, "original_score" %>
          <br>
          Director: <%= rating_for @movie, "original_score" %>
          <br>
          Custome Design: <%= rating_for @movie, "custome_design" %>
        <% end %>
      </div>
    </div>

     

    NOTE: If you want to use IMDB like rating average and auto hide stars after staring use following:

    <strong>Review Score: </strong><%= rating_for @event, "original_score", disable_after_rate: true, imdb_avg: true %>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: