2016-06-01 5 views
1

Ich benutze Schienen 5@ project.impressionist_count - falsche Anzahl von Argumenten (2 gegeben, erwartet 0..1)

Ich möchte

die Anzahl der Ansichten des Projekts zählen, die ich gem 'impressionist'

installiert

die Migration Eindrücke Tabelle generieren

rails g impressionist 

Führen Sie die Migration

rake db:migrate 

Im Hinblick Projekten/show.html.erb

<%= @project.impressionist_count %> 

angezeigt Fehler in Zeile <% = @ project.impressionist_count%> falsche Anzahl an Argumenten (2 gegeben, erwartet 0..1) I Ich bin nicht in der Lage, die Ursache des Fehlers zu identifizieren.

Logs:

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) 

In Schienen Konsole:

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' 

Modellprojekt

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 

Antwort

0

Ihr Modell sollte wie:

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

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

end 

In Controller:

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

i Impressionist hinzugefügt sind :: IsImpressionable. reloaded server same error – Dmitriy

+0

auskommentieren 'impressionist (@project)' von Controller show Methode kann das Problem lösen. – Emu

+0

falsche Anzahl von Argumenten (gegeben 2, erwartet 0..1) – Dmitriy