I’m trying to implement a star rating system in my rails application. I’ve opted to use ajaxful-rating gem for this.
- I’ve installed the Gem
- I’ve ran the script
- I’ve added ajaxful_rateable to my gear model to enable rating them.
- I’ve added ajaxful_rater to my user model to enable rating other items.
I’m not completely through the installation because I’m running into errors with the routes. I need to know what I’m doing wrong on the routes or database. From the instructions on the gem it didn’t seem that I needed to augment the database except to cache the average rating. But I’m getting the following error when I try to access the view
Mysql2::Error: Table 'equiptme.rates' doesn't exist: SHOW FULL FIELDS FROM `rates`
Please help. My code is below.
Routes
resources :gears, :member => {:rate => :post} do
resources :calendars, :only => [:create, :destroy, :edit]
resources :comments, :only => [:create, :destroy]
end
View
<% @comments.each do |comment| %>
<div style="width: 99%; min-height: 190px; margin-bottom: 30px; border-bottom: 1px dotted #DAD9D9;">
<div style="width: 17%; float: left; overflow: hidden; margin-left: 10px; text-align: center; font-size: 14px; ">
<div class="gearcomments_userpic_container"><%= image_tag comment.user.userimage.url(:comments), :class => "gearcomments_userpic" %></div></br>
<%= comment.user.name %>
</div>
<div style="width: 55%; float: left; margin-left: 10px; font-size: 13px;">
<%= comment.body %>
</div>
<div style="width: 15%; float: left; text-align: center;">
<h4>Overall Rating</h4></br>
<%= ratings_for @gear, :show_user_rating => true %>
<div></div></br>
<% # display delete link only for comments written by this particular user %>
<% if user_signed_in? and comment.user_id == current_user.id %>
<span><%= link_to 'delete', gear_comment_path(@gear, comment), :confirm => 'Are you sure?', :method => :delete, :class => "" %></span>
<% end %>
</div>
</div>
<% end %>
Gear Model
class Gear < ActiveRecord::Base
...
ajaxful_rateable :stars => 6, :allow_update => true
end
User Model
class User < ActiveRecord::Base
...
ajaxful_rater
end
You are missing a table in your database (probably required by the gem). Are you sure you have migrated your database?
You must run the script which probably generates migrations, but then you must also:
or
bundle exec rake db:migrateif required.Make sure that you have run the generate script (from the README):
This section in the README definitely implies a migration is generated.