2016-06-01 114 views
1

我用導軌5@ project.impressionist_count - 錯誤的參數數目(2給出,預計0..1)

我想算的意見

我安裝項目的數量gem 'impressionist'

生成印象表遷移

rails g impressionist 

運行遷移

rake db:migrate 

鑑於項目/ show.html.erb

<%= @project.impressionist_count %> 

上線<%= @ project.impressionist_count%>錯誤的參數數目(2給出,預期0..1)我顯示的錯誤我無法確定錯誤的原因。

日誌:

app/views/projects/show.html.erb:89:in `_app_views_projects_show_html_erb___149972252570834158_69970117978380' 
    Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout 
    Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb 
    Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (8.9ms) 
    Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb 
    Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (5.1ms) 
    Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb 
    Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.7ms) 
    Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (121.7ms) 
DEPRECATION WARNING: #original_exception is deprecated. Use #cause instead. (called from status_code_with_paginate at /usr/local/rvm/gems/ruby-2.3.0/gems/will_paginate-3.1.0/lib/will_paginate/railtie.rb:49) 

在軌控制檯:

pry(main)> project.impressionist_count 
ArgumentError: wrong number of arguments (given 2, expected 0..1) 
from /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/associations/collection_proxy.rb:731:in `count' 

示範工程

class Project < ActiveRecord::Base 
.......................... 

    is_impressionable 

............................. 

end 

ProjectsController

class ProjectsController < ApplicationController 
    before_action :set_project, only: [:show, :edit, :update] 
    before_action :authenticate_user!, only: [:new, :edit] 
    before_action :require_permission, only: [:edit] 
    before_action :set_freelancer, only: [:show] 
    before_action :set_response_current_user, only: :show, if: :exist_response? 
    after_action :verify_authorized, only: [:update] 

    impressionist :actions => [:show] 

    def show 
     @new_response = @project.responses.build 
     impressionist(@project) 
    end 
............................................... 
end 

回答

0

模式應該是這樣的:

class Project < ActiveRecord::Base 
.......................... 
    include Impressionist::IsImpressionable 
    is_impressionable 

............................. 

end 

控制器

def show 
    @new_response = @project.responses.build 
    # impressionist(@project) //comment out this line 
end 
+0

我加入包括印象派:: IsImpressionable。重新加載服務器同樣的錯誤 – Dmitriy

+0

從控制器顯示方法註釋掉'impressionist(@project)'可能會解決問題。 – Emu

+0

錯誤的參數數量(給定2,預期0..1) – Dmitriy

相關問題