I spent all my time yesterday trying to get ANY Rails tagging plugin to work. While installation was straightforward, I have to say the amount of documentation on how to use any of these plugins was dismal at best...
For the record, I trie开发者_StackOverflow社区d:
is_taggable acts_as_taggable_on acts_as_taggable_on_steroids acts_as_taggable_redux
In every instance, the documentation consisted of something like this:
- install
- undefined magic <---(This is where I fell over, What do I put in my Models, Views and Controllers to make your awesome plugin work? Please tell me!)
- Check out all these cool features!
With all of the plugins, I'd ended up dealing with errors like:
NoMethodError in ItemsController#create undefined method `tag_list=' for #<Item:0x47fe848>
I looked up the issues raised on the respective plugin's websites and found that I'm definitely not the only one with these issues. But author support/explanation was not forthcoming even though most of these issues had been raised a while back.
I understand that if I was some kind of Rails guru I could probably get the plugin to work. But I'm not. In my frustration I've decided to just roll my own tagging implementation which seems stupid considering there's so many plugins for tagging available out there...
I also have to say I'm a bit concerned that most of these plugins haven't been maintained in a while. Which makes me wonder if they'll be brought over to Rails 3.
If anyone knows of a tagging plugin for Rails that really works and is easy to implement, please let me know (and if you could point me to a decent tutorial I will give you my undying gratitude as well as some amazing pieces of fluff I found in my pocket just then...)
Otherwise, let this be a plea from all those beginner/intermediate Rails programmers out there to the Rails gods who make and maintain plugins... "We love your work, but please, please provide more documentation!"
I have used mbleigh's acts-as-taggable-on, and the basic procedure goes:
- Add
config.gem "acts-as-taggable-on"
to environment.rb - Run
rake gems:install
- Run
script/generate acts_as_taggable_on_migration
- Do any customizations on the migration you might want (you probably won't need to).
- Run the migration,
rake db:migrate
- Add
acts_as_taggable_on :your_desired_tag_names
to your tagged model (pluralized).- I.e. Photo model has
:colors
tag. - If you are getting a
NoMethodError
, you may have skipped this step.
- I.e. Photo model has
- To set the models tags, use
photo.color_list = 'abc, 123, def, 456'
- Save the model:
photo.save
- List the tags:
photo.colors
- You might have to reload the model from the database for the
photo.colors
method to be available.
- You might have to reload the model from the database for the
Check out the acts-as-taggable-on readme for more instructions/examples.
Crazy World!
I also managed to get acts_as_taggable_on_steroids working today...
The missing link was that you needed to add this to ApplicationHelper:
include TagsHelper
This was mentioned in the readme but only under the "Tag Clouds" section so it wasn't clear that you needed to add it for any of the methods to be recognized in the first place...
精彩评论