2012-09-03 143 views
1

我試圖在我的rails應用程序中實現星級評分系統。我選擇使用ajaxful-rating寶石。rails星級評分系統 - ajaxful評級

  • 我已經安裝了寶石
  • 我跑我添加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 

回答

2

你缺少你的數據庫中的表(可能是由寶石需要)。你確定你已經遷移你的數據庫嗎?

您必須運行這可能產生遷移腳本,但你還必須:

rake db:migrate 

,或者如果需要bundle exec rake db:migrate


確保您已運行生成腳本(自述):

script/generate ajaxful_rating UserModelName 

發生器有一個參數:UserModelName,這是 當前用戶模型的名稱。這是鏈接率和 用戶模型所必需的。

而且這臺發電機複製necesary圖像,款式等

例子:我想你已經生成的驗證模型...

script/generate authenticated user sessions 
script/generate ajaxful_rating user 

所以這個調用將創建一個速率模型,並將鏈接它給你的用戶 模型。

自述文件中的這一部分明確暗示生成了遷移。

+0

哇......我不敢相信我錯過了那個。謝謝! – DaveG