2012-09-03 145 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