agged_with(params[:skill]) ArgumentError: wrong number of arguments (given 2, expected 1)
agged_with(params[:skill]) ArgumentError: wrong number of arguments (given 2, expected 1)
我在 Rails 5 beta 3 中对 gem acts-as-taggable-on 有疑问。
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
在线 @projects = Project.tagged_with(params[:skill])
我收到以下错误:
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'
看起来 tagged_with
正在内部调用 quote_value
,这是 sanitize
的 alias_method
。
sanitize
只需要一个参数,但 tagged_with
调用 quote_value
有两个参数,这就是问题所在。
参考acts_as_taggable, ActiveRecord::Sanitization和
commit 引入了此更改。
他们解决了这个问题。从 Gemfile 中的 master
分支下载:
gem 'acts-as-taggable-on', :github => 'mbleigh/acts-as-taggable-on', :branch => 'master'
我在 Rails 5 beta 3 中对 gem acts-as-taggable-on 有疑问。
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
在线 @projects = Project.tagged_with(params[:skill])
我收到以下错误:
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'
看起来 tagged_with
正在内部调用 quote_value
,这是 sanitize
的 alias_method
。
sanitize
只需要一个参数,但 tagged_with
调用 quote_value
有两个参数,这就是问题所在。
参考acts_as_taggable, ActiveRecord::Sanitization和 commit 引入了此更改。
他们解决了这个问题。从 Gemfile 中的 master
分支下载:
gem 'acts-as-taggable-on', :github => 'mbleigh/acts-as-taggable-on', :branch => 'master'