データベースの中にたくさんのタグを作成しようとしていますが、誰も宝石でこれを行う方法を知っていますか?acts-as-taggable-on?どのようにdb:タグ付け可能なタグとして私の行為をシード?
Productsテーブル:
create_table :products do |t|
t.string :name
t.date :date
t.decimal :price, :default => 0, :precision => 10, :scale => 2
t.integer :user_id
end
と:tag_list
フィールドは、ActsAsTaggableOn
の移行によって作成された仮想列です:
class ActsAsTaggableOnMigration < ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.string :name
end
create_table :taggings do |t|
t.references :tag
# You should make sure that the column created is
# long enough to store the required class names.
t.references :taggable, :polymorphic => true
t.references :tagger, :polymorphic => true
t.string :context
t.datetime :created_at
end
add_index :taggings, :tag_id
add_index :taggings, [:taggable_id, :taggable_type, :context]
end
def self.down
drop_table :taggings
drop_table :tags
end
end
これは私の製品/形で私の:tag_list
フィールドです。 html.erb
<div class="field">
<%= f.label :tag_list %>:
<%= f.text_field :tag_list %>
</div>
私は
Product.create([
{:tag_list => 'Foods'},
{:tag_list => 'Electronics'},
{:tag_list => 'Pizza'},
{:tag_list => 'Groceries'},
{:tag_list => 'Walmart'},
{:tag_list => 'Apples'},
{:tag_list => 'Oranges'} ])
....このような何かをしようとしたが、RoRのスキルの私の欠如は、これは間違った方法であると私は、任意の提案を助けが必要と言われますか?
を行うことで、タグをシードできおかげで、感謝します! – LearningRoR
それはあなたのために働いてうれしい。 – Brian