views:

20

answers:

2

I have a model Post that has_many :tags

I want to do:

Post.create({:tags => ['tag1', 'tag2']})

How can I make that work?

+1  A: 

Might be able to do that with Nested Attributes.

Corey
This is close to what I want, but I'd like to be able to use an array of strings directly, and I'd also like it to associate with the existing object if there is one.
singpolyma
In that case you'll probably need to add a virtual attribute to your Post model and create the tags in there.
Corey
A: 

Use the acts-as-taggable-on gem.

class Post < ActiveRecord::Base
  acts_as_taggable_on :tags
end

Post.create(:tag_list => ['tag1', 'tag2'])
KandadaBoggu