在activerecord信誉系统中未定义的方法错误“reputation_value_for”

时间:2014-02-04 17:21:28

标签: ruby-on-rails-4 rails-activerecord

我是rails的新手,我想在我的应用程序中创建投票。我一直关注activerecord-reputation-gem的railscasts剧集。 http://railscasts.com/episodes/364-active-record-reputation-system

我正面临错误==未定义方法错误的声誉声誉_value_for

我从

下载了宝石
  • gem'activerecord-reputation-system',github: 'NARKOZ / activerecord-reputation-system',分支:'rails4'

我的帖子.rb是

    class Post < ActiveRecord::Base
has_many :comments
belongs_to :cubestudent

validates_presence_of :body, :title, :subject
has_reputation :votes, source: :cubestudent, aggregated_by: :sum
    end

cubestudent.rb

   class Cubestudent < ActiveRecord::Base
   # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
     devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
      has_many :evaluations, class_name: "RSEvaluation", as: :source
     has_many :posts, :dependent => :destroy
     has_many :comments, :dependent => :destroy
       has_reputation :votes, source: {reputation: :votes, of: :posts}, aggregated_by: :sum


      def voted_for?(post)
       evaluations.where(target_type: post.class, target_id: post.id).present?
        end

      end

posts.controller

  class PostsController < ApplicationController
  before_action :set_post, only: [:show, :edit, :update, :destroy]

  def create
  @post = Post.new(post_params)
   @post.postedby = current_cubestudent.email
    @post.postedbyid = current_cubestudent.id

    respond_to do |format|
  if @post.save
    format.html { redirect_to @post, notice: 'Post was successfully created.' }
    format.json { render action: 'show', status: :created, location: @post }
  else
    format.html { render action: 'new' }
    format.json { render json: @post.errors, status: :unprocessable_entity }
  end
   end
   end

  def destroy
  @post.destroy
  respond_to do |format|
  format.html { redirect_to posts_url }
  format.json { head :no_content }
   end
  end

   def new
   @post = Post.new
    end

   def index
   @posts = Post.find_with_reputation(:votes, :all, order: "votes desc") 

   end

  def show
   end

   def edit
   end

   def update
    respond_to do |format|
     if @post.update(post_params)
    format.html { redirect_to @post, notice: 'Post was successfully updated.' }
    format.json { head :no_content }
     else
    format.html { render action: 'edit' }
    format.json { render json: @post.errors, status: :unprocessable_entity }
    end
    end
   end

   def  vote
     value = params[:type] == "up" ? 1 : -1
       @post = Post.find(params[:id])
       @post.add_or_update_evaluation(:votes, value, current_cubestudent)
       redirect_to :back, notice: "Thank you for voting"
       end





   private
      # Use callbacks to share common setup or constraints between actions.
     def set_post
    @post = Post.find(params[:id])
     end

     # Never trust parameters from the scary internet, only allow the white list through.
      def post_params
     params.require(:post).permit(:title, :body, :subject)
         end
     end

_post.html.erb

     <h4 class="timeline-title"><%= link_to_unless_current post.title, post %></h4>
  <p> Created : <%= post.created_at.strftime("%d/%m/%Y") %> by <%= post.postedby %>
</p>
 <%= simple_format post.body , :class => "timeline-body"%>
 <%= pluralize post.reputation_value_for( :votes).to_i, "vote" %>
 <% if current_cubestudent && !current_cubestudent.voted_for?(post) %>
 <%= link_to "up", vote_post_path(post, type: "up"), method: "post" %>
 <%= link_to "down", vote_post_path(post, type: "down"), method: "post" %>
 <% end %>

我无法确定为什么会出现此错误,任何人都可以帮助我? 提前致谢

my gemfile

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
gem 'cancan'
gem 'devise'
gem 'kaminari'
gem 'twitter-bootstrap-rails'
gem 'pg'
gem 'activerecord-reputation-system', github: 'NARKOZ/activerecord-reputation-system', branch: 'rails4'
#gem 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git"
#gem 'activeadmin', github: 'gregbell/active_admin'

 # Use SCSS for stylesheets
 gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more:   https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

 # Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

1 个答案:

答案 0 :(得分:5)

它已被弃用。请改用reputation_for