Ruby on rails rubyonrails中的Ajax/Increment计数器投票方法

Ruby on rails rubyonrails中的Ajax/Increment计数器投票方法,ruby-on-rails,ruby,ajax,ruby-on-rails-3,jquery,Ruby On Rails,Ruby,Ajax,Ruby On Rails 3,Jquery,我不确定我做错了什么,非常困惑。我正在尝试制作一个像旧的Digg.com评级计数器一样的评级计数器。谁能看一下我的代码并帮我一下吗 需要注意的是,以下是单独的数据库表/模型:Rate、Post、User 评分:用户id整数、发布id整数和评分计数整数默认值=>0 Post:评级\u count整数默认值=>0 这就是我目前正在使用的,所有的代码,我有这个评级系统,如果它没有显示,那么我没有它,因此失踪,并希望有人能帮助指出什么是失踪。多谢各位 费率控制器 class RateController

我不确定我做错了什么,非常困惑。我正在尝试制作一个像旧的Digg.com评级计数器一样的评级计数器。谁能看一下我的代码并帮我一下吗

需要注意的是,以下是单独的数据库表/模型:
Rate、Post、User

评分:
用户id整数、发布id整数和评分计数整数默认值=>0

Post:
评级\u count整数默认值=>0

这就是我目前正在使用的,所有的代码,我有这个评级系统,如果它没有显示,那么我没有它,因此失踪,并希望有人能帮助指出什么是失踪。多谢各位

费率控制器

class RateController < ApplicationController
  def create
    @post.increment_counter(:ratings_count, params[:id]) if params[:ratings_count]
    respond_to do |format|
      format.html { redirect_to @user }
      format.js
    end
  end

  def increment_counter(counter_name, id)
    update_counters(:post, :ratings_count => 1)
  end
end
class RateController1)
结束
结束
费率模型

class Rate < ActiveRecord::Base
  attr_accessible :post_id, :user_id, :ratings_count
  has_many :posts
  has_many :users

  validates :post_id, presence: true
  validates :user_id, presence: true

end
class Micropost < ActiveRecord::Base
  attr_accessible :ratings_count
  belongs_to :user
  has_many :ratings

  validates :ratings, presence: true
end
class Rate
费率表

<%=form_for @rate do |f|%>
<%= f.hidden_field :ratings_count %>
<%=f.submit "Rate"%>
<%end%>

微成本模式

class Rate < ActiveRecord::Base
  attr_accessible :post_id, :user_id, :ratings_count
  has_many :posts
  has_many :users

  validates :post_id, presence: true
  validates :user_id, presence: true

end
class Micropost < ActiveRecord::Base
  attr_accessible :ratings_count
  belongs_to :user
  has_many :ratings

  validates :ratings, presence: true
end
class Micropost
create.js.erb for rate

$("#rates").html("Rates: <%= @micropost.ratings_count.count %>")
$(“#费率”).html(“费率:)
查看宝石。 使用此gem,您只需将其包含到您的模型中:

  • 扮演可呕吐的角色
并为控制器添加一些逻辑