Stefan Hansch
Stefan Hansch

Reputation: 1590

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'

Upvotes: 0

Views: 2777

Answers (2)

Alex
Alex

Reputation: 392

They fixed this. Download from the master branch, in your Gemfile:

gem 'acts-as-taggable-on', :github => 'mbleigh/acts-as-taggable-on', :branch => 'master'

Upvotes: 0

Dharam Gollapudi
Dharam Gollapudi

Reputation: 6438

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.

Upvotes: 6

Related Questions