Star Rating Like Amazon Google In ruby On Rails Web Application

Total Blog Views: 44

Blog Status: publish

Created By: swazahmad Created at: 08-08-2021

Tags: ruby on rails rails 07 star-rating

As In the current Technology world Every one wants the dynamic feature in there website in day to dy use

So We will learn today

How to Start Rating Like Amazon In Ruby On Rails?

We Will Create a Sample App For the same

  • Create a New Rails StarRateApp

$ rails new StarRateApp

  •  Then We will Create A Item Module In The application By using Below Command

$ rails g scaffold Blog title:string body:text

Note: The above command will create All the files required For Blog Module(Model View Controller), Then Run Below Command

$ rails db:create db:migrate

  • Update the routes.rb File

Rails.application.routes.draw do
  resources :blogs
  root 'blogs#index'
end

Now The sample Application is ready Now You can Run $ rails s and check your application then add some sample Items

  • From Here the actual Review Feature started add Below Line in your Gemfile

gem 'ratyrate'

gem 'devise' #If not present

After Adding the Gem Run Bundle Install

$ bundle install

Then We need to configure the User module

$ rails g ratyrate user 

We are Considering you will have a devise user model which name is User. The devise generator and ratyrate generator should be like below Note: If devise is not configured then run below 2 commands

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

 

  • Then Include The required Javascripts File in application.js

//= require jquery.raty
//= require ratyrate

 

  • Update the user.rb Model File.

class User.rb < ApplicationRecord

  ratyrate_rater

end

  • Update The blog.rb File

class Blog < ApplicationRecord

  ratyrate_rateable "blog_content", "presentation", "blogger"
end

  • The Final and Main Page Need to update the blogs/index.html.erb update the raty/rate show code to review     

<p>
                Blog Content  : <%= rating_for @blog, 'blog_content', disable_after_rate: true %>
                Presentation : <%= rating_for @blog, 'presentation', disable_after_rate: true %>
                Blogger(User added Blog) : <%= rating_for @blog, 'blogger', disable_after_rate: true %>
</p>

  • Then start You rails application

$ rails s

 

Note: You can ask any question in comment

The Below start is the exact example of rating of above Blog


swazahmad

Swaz is Practice Lead of ROR Developer. he's a Blogger, Mentor, and Rubyst. He has expertise in Javascript also . he's highly skilled in designing, developing and testing web applications. He enjoys being challenged and interesting with projects that need him to



Comments



  • swazahmad | almost 4 years ago
    Awesome Information Thanks For Sharing
Buy traffic for your website

About Shadbox

we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.

Services

Downloads