spanner / radiant-taggable-extension

This is another tagging solution for radiant: more versatile but less to the point than the tags extension.
spanner.org/radiant/taggable
14 stars 7 forks source link

Migration fails for pages with no keywords #10

Open pelargir opened 14 years ago

pelargir commented 14 years ago

Installing the extension under Radiant 0.9.1 and I ran into an issue with the 002_import_keywords.rb migration. If a page doesn't have any keywords assigned I get this error when I run the migration:

NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
from [RAILS_ROOT]/vendor/radiant/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:320:in `replace'
from [RAILS_ROOT]/vendor/radiant/vendor/rails/activerecord/lib/active_record/associations.rb:1331:in `attached_tags='
from [RAILS_ROOT]/vendor/extensions/taggable/lib/taggable_model.rb:124:in `tags_from_keywords'
from (irb):4

If I assign keywords to the page first, the migration runs successfully.

fatangel commented 14 years ago

just add a condition like:

Page.find(:all).each do |page|
    page.tags_from_keywords if !page.keywords.empty?
end