开发者

Getting rails tagging plugins to work makes me Hulk-angry

开发者 https://www.devze.com 2022-12-20 11:18 出处:网络
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 d

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:

  1. install
  2. 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!)
  3. 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:

  1. Add config.gem "acts-as-taggable-on" to environment.rb
  2. Run rake gems:install
  3. Run script/generate acts_as_taggable_on_migration
    • Do any customizations on the migration you might want (you probably won't need to).
  4. Run the migration, rake db:migrate
  5. 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.
  6. To set the models tags, use photo.color_list = 'abc, 123, def, 456'
  7. Save the model: photo.save
  8. List the tags: photo.colors
    • You might have to reload the model from the database for the photo.colors method to be available.

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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号