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

社会主义新天地 提交于 2019-12-12 03:31:49

问题


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'


回答1:


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.




回答2:


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

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


来源:https://stackoverflow.com/questions/36029576/agged-withparamsskill-argumenterror-wrong-number-of-arguments-given-2-ex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!