私の Rails プロジェクトでは、Formtastic を使用してフォームを管理しています。「グループ」という列を持つモデルのタグがあります。グループ列は、タグを整理するための単純なハードコーディングされた方法です。タグモデルクラスを投稿して、それがどのように構成されているかを確認できるようにします
class Tag < ActiveRecord::Base
class Group
BRAND = 1
SEASON = 2
OCCASION = 3
CONDITION = 4
SUBCATEGORY = 5
end
has_many :taggings, :dependent => :destroy
has_many :plaggs, :through => :taggings
has_many :monitorings, :as => :monitorizable
validates_presence_of :name, :group
validates_uniqueness_of :name, :case_sensitive => false
def self.brands(options = {})
self.all({ :conditions => { :group => Group::BRAND } }.merge(options))
end
def self.seasons(options = {})
self.all({ :conditions => { :group => Group::SEASON } }.merge(options))
end
def self.occasions(options = {})
self.all({ :conditions => { :group => Group::OCCASION } }.merge(options))
end
def self.conditions(options = {})
self.all({ :conditions => { :group => Group::CONDITION } }.merge(options))
end
def self.subcategories(options = {})
self.all({ :conditions => { :group => Group::SUBCATEGORY } }.merge(options))
end
def self.non_brands(options = {})
self.all({ :conditions => [ "`group` != ? AND `group` != ?", Tag::Group::SUBCATEGORY, Tag::Group::BRAND] }.merge(options))
end
end
私の目標は、Formtastic を使用して、グループ化された複数選択ボックスを提供し、列「グループ」でグループ化し、non_brands メソッドから返されるタグを付けることです。私は次のことを試しました:
= f.input :tags, :required => false, :as => :select, :input_html => { :multiple => true }, :collection => tags, :selected => sel_tags, :group_by => :group, :prompt => false
しかし、次のエラーが表示されます。
(nil:NilClass の未定義メソッド「クラス」)
私が間違っているアイデアはありますか?
見てくれてありがとう:]