Rails5を使っています
プロジェクトの閲覧数をカウントしたい
インストールしました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
プロジェクトコントローラー
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