views:

45

answers:

2

Ok, so you know how you ask a question here, and in the "Tags" field you can enter several space-separated tags into a single text field?

I'm trying to replicate similar behavior in my Rails app. Except instead of questions, I'm doing a blog app (which has "posts"), and tagging those.

I'm using "form_for" to build the quick form. Inside of that I have the line:

f.text_field :tags

The problem I'm running into is, "tags" is not a field on my Post class. My Post class HABTM tags. So, somehow I need to parse the tags text field (using String.split), and pass the resulting tag Strings into my controller, so my controller can create and associated the tags along with the new blog post.

Is using "form_for" not going to work in this case? Is doing this sort of behavior beyond the design of the quick-and-dirty "form_for" functionality?

Thanks!

+1  A: 

Unless you really want to reinvent the wheel, I would suggest using a plugin for this. ActsAsTaggableOnSteroids is a mature one. http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids

Ben
:) I do not want to reinvent the wheel. I shall dig into that link.Thanks!
normalocity
Works like a charm. Thanks, man.
normalocity
you're welcome.
Ben
A: 

Agree with Ben on this - there's lots of great plugins and features/helpers that make them simple to use. And you can learn a lot about how to do this in a well-designed way. Here's another good choice.

http://github.com/mbleigh/acts-as-taggable-on

Swards