LoginSignup
1
0

More than 5 years have passed since last update.

acts_as_taggableのfixtureの書き方

Posted at

ポイントは

  1. fixtureのファイルをacts_as_taggable_onの下に置く
  2. taggingの方でcontextを指定する(generatorが作るfixtureにはない)
# models/post.rb
class Post < ActiveRecord::Base
  acts_as_taggable
end

# fixtures/posts.yml
one: {}
two: {}

# fixtures/acts_as_taggable_on/tags.yml
tag_one:
  name: good
tag_two:
  name: bad

# fixtures/acts_as_taggable_on/taggings.yml
tag_one
  taggable: one (Post)
  context: tags
  tag: tag_one
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0