Search code examples
ruby-on-railsajaxrating

rails star rating system - ajaxful-rating


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

Solution

  • 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:

    rake db:migrate
    

    or bundle exec rake db:migrate if required.


    Make sure that you have run the generate script (from the README):

    script/generate ajaxful_rating UserModelName
    

    The generator takes one argument: UserModelName, which is the name of your current user model. This is necessary to link both the rate and user models.

    Also this generator copies the necesary images, styles, etc.

    Example: I suppose you have generated already an authenticated model…

    script/generate authenticated user sessions
    script/generate ajaxful_rating user
    

    So this call will create a Rate model and will link it to your User model.

    This section in the README definitely implies a migration is generated.