Created by Myriam Leggieri, @iammyr for Rails Girls Galway The basic guides that have been merged and adapted are the Ruby on Rails Tutorial, the basic RailsGirls app and the tutorials for creating thumbnails, authenticating users, adding design, deploying to OpenShift and adding comments.
What do we want our app to do? As a first thing, we would like to
- authenticate users
- allow authenticated users to create a new touristic place description
- allow authenticated users to comment those places
- allow authenticated users to rate up to which extent those places are autism-friendly or not.
We modeled and deployed comment, user and place resources, so far. Let’s now enable the rating for places.
Step 0: Add letsrate gem
Open up your
Gemfile and add this line
to install the gem. Also remember to restart the Rails server.
Step 1: Set up letsrate in your app
Run the following command in the terminal. (we are assuming that we had already enabled authenticated users using the
Step 2: Apply letsrate to your resource
You should add the
letsrate_rateable function with its dimensions option, to the model of the resource you wish to rate, i.e., place. You can have multiple dimensions.
Then you need to add a call
letsrate_rater in the user model:
Step 3: Render the Views
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 new rating value from authenticated user.
app/views/places/show.html.erb and add
You can use the
rating_for_user helper method to show the star rating for the user.
That’s it! ^__^ Try it out by restarting the server, add, commit and push on GitHub. If all it’s working then you can also deploy ;)