我正在尝试使用acts_as_taggable 插件在我的ruby on rails 应用程序中包含标签功能。我附上了代码。我已经安装了插件并运行了迁移。我收到以下错误。
undefined method `each' for "value of the parameter":String
代码
location.rb - 位置表有名称、标签(这是我在表中的一个附加字段,我在了解插件之前添加了它:)、城市字段
class Location < ActiveRecord::Base
belongs_to :profile
acts_as_taggable
end
配置文件.rb
class Profile < ActiveRecord::Base
has_many :locations
acts_as_tagger
end
location_controller.rb
def create
@location = Location.new(params[:location])
@location.tag_list = ["tags1","tags2"]
if @location.save
redirect_to(@location)
else
redirect_to(@profile)
end
end
应用程序跟踪
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:320:in `replace'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/associations.rb:1331:in `block in collection_accessor_methods'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:2906:in `block in assign_attributes'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in `assign_attributes'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:2775:in `attributes='
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:2473:in `initialize'
/Users/felix/rails_projects/sample_app/app/controllers/locations_controller.rb:92:in `new'
/Users/felix/rails_projects/sample_app/app/controllers/locations_controller.rb:92:in `create'
谢谢