Skip to content

Migration fails for pages with no keywords #10

Description

@pelargir

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.

Activity

  1. fatangel commented on Oct 27, 2010

    @fatangel

    just add a condition like:

    Page.find(:all).each do |page|
        page.tags_from_keywords if !page.keywords.empty?
    end
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions