Railsアプリケーションに星評価システムを実装しようとしています。私はこれにajaxful-ratinggemを使用することを選択しました。
- Gemをインストールしました
- スクリプトを実行しました
- ギアモデルにajaxful_rateableを追加して、それらを評価できるようにしました。
- 他のアイテムの評価を可能にするために、ユーザーモデルにajaxful_raterを追加しました。
ルートでエラーが発生しているため、インストールが完全に完了していません。ルートまたはデータベースで何が間違っているのかを知る必要があります。宝石の説明から、平均評価をキャッシュすることを除いて、データベースを拡張する必要はないようでした。しかし、ビューにアクセスしようとすると、次のエラーが発生します
Mysql2::Error: Table 'equiptme.rates' doesn't exist: SHOW FULL FIELDS FROM `rates`
助けてください。私のコードは以下の通りです。
ルート
resources :gears, :member => {:rate => :post} do
resources :calendars, :only => [:create, :destroy, :edit]
resources :comments, :only => [:create, :destroy]
end
意見
<% @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 %>
ギアモデル
class Gear < ActiveRecord::Base
...
ajaxful_rateable :stars => 6, :allow_update => true
end
ユーザーモデル
class User < ActiveRecord::Base
...
ajaxful_rater
end