Stefan Hansch Stefan Hansch - 7 months ago 159
Ruby Question

agged_with(params[:skill]) ArgumentError: wrong number of arguments (given 2, expected 1)

I have issue with gem acts-as-taggable-on in Rails 5 beta 3.

project.rb​:

class Project < ActiveRecord::Base
acts_as_taggable
acts_as_taggable_on :skills
end


routes.rb

get 'tags/:skill', to: 'projects#index', as: :skill


projects_controller.rb:

class ProjectsController < ApplicationController
def index
if params[:category] && Category.exists?(params[:category])
@category = Category.find(params[:category])
@projects = @category.projects.order("projects.created_at DESC")
elsif params[:skill]
@projects = Project.tagged_with(params[:skill])
else
@projects = Project.all
end

@categories = Category.all
end
end


On line
@projects = Project.tagged_with(params[:skill])
I get the following error:


ArgumentError: wrong number of arguments (given 2, expected 1) from
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-5.0.0.beta3/lib/active_record/sanitization.rb:8:in
`sanitize'

Answer

Looks like tagged_with is calling quote_value internally, which is an alias_method for sanitize.

sanitize expects only one argument, but the tagged_with is calling quote_value with two arguments, which is causing the issue.

Refer to acts_as_taggable, ActiveRecord::Sanitization and the commit that introduced this change.