在选民部分中错误的参数数量(0表示1)

时间:2014-09-29 23:05:39

标签: ruby arguments

Showing /home/vagrant/code/bloccit/app/views/votes/_voter.html.erb where line #6 raised:

wrong number of arguments (0 for 1)
Extracted source (around line #6):


    <div><%= link_to " ", 
        post_up_vote_path(post), 
        class: up_vote_link_classes(post), method: :post %>
    </div>
    <div>
        <strong>

模板包含跟踪:app / views / posts / _post.html.erb,app / views / topics / show.html.erb

Rails.root:/ home / vagrant / code / bloccit

应用程序跟踪|框架跟踪|完整追踪 app / models / user.rb:20:in voted' app/models/user.rb:21:in投票' app / helpers / application_helper.rb:26:in up_vote_link_classes' app/views/votes/_voter.html.erb:6:in _ app_views_votes__voter_html_erb___418536146_80757250' app / views / posts / _post.html.erb:2:in _app_views_posts__post_html_erb___621990029_79333610' app/views/topics/show.html.erb:10:in _ app_views_topics_show_html_erb__712368041_99038610' 请求

参数:

{ “ID”=&gt; “中1”} 切换会话转储 切换env转储 响应

接头:

在我的选民部分

<% if policy(Vote.new).create? %>
<div class="vote-arrows pull-left">

    <div><%= link_to " ", 
        post_up_vote_path(post), 
        class: up_vote_link_classes(post), method: :post %>
    </div>
    <div>
        <strong>
            <%= post.points %>
        </strong>
    </div>
    <div><%= link_to " ", 
        post_down_vote_path(post), 
        class: down_vote_link_classes(post), method: :post %>
    </div>
</div>  
<% end %>

user.rb

class User < ActiveRecord::Base
 # Include default devise modules. Others available are:
 # :confirmable, :lockable, :timeoutable and :omniauthable
 devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable, :confirmable
has_many :posts, dependent: :destroy 
  mount_uploader :avatar, AvatarUploader
has_many :comments, dependent: :destroy
has_many :votes, dependent: :destroy
has_many :favorites, dependent: :destroy

def role?(base_role)
    role == base_role.to_s
end  

def favorited(post)
  favorites.where(post_id: post.id).first
end  

def voted(post)
  voted.where(post_id: post.id).first
end   

def self.top_rated
  self.select('users.*') # Select all attributes of the user
      .select('COUNT(DISTINCT comments.id) AS comments_count') # Count comments made my the user
      .select('COUNT(DISTINCT posts.id) AS posts_count') # Count the posts made by the user
      .select('COUNT(DISTINCT comments.id) + COUNT(DISTINCT posts.id) AS rank') # Add the comment count to the post count and label the sum as "rank"
      .joins(:posts) # Ties the posts table to the users table, via the user_id
      .joins(:comments) # Ties the comments table to the users table, via the user_id
      .group('users.id') # Instructs the database to group the results so that each user will be returned in a distinct row
      .order('rank DESC') # Instructs the database to order the results in descending order, by the rank that we created in this query. (rank = comment count + post count)
end       
end

1 个答案:

答案 0 :(得分:0)

您的voted方法中存在拼写错误,您递归调用voted,而不是votes。投票期待一个参数,因此你有一个错误。将其更改为:

def voted(post)
  votes.where(post_id: post.id).first
end