0

I think I have it setup properly per these answers

But when I'm trying to update the slug column in an existing app like so for my tags:

Tag.find_each(&:save)

I'm getting this error:

NameError: uninitialized constant Tag

Is Tag not the correct one?


EDIT: FULL ERROR LOG

  ActsAsTaggableOn::Tag Load (0.8ms)  SELECT  "tags".* FROM "tags"  ORDER BY "tags"."id" ASC LIMIT 1000
   (0.2ms)  BEGIN
   (0.4ms)  ROLLBACK
NoMethodError: undefined method `slugged' for #<ActsAsTaggableOn::Tag:0x007faafaefc458>
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activemodel-4.2.2/lib/active_model/attribute_methods.rb:433:in `method_missing'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/friendly_id-5.1.0/lib/friendly_id/slugged.rb:295:in `should_generate_new_friendly_id?'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/friendly_id-5.1.0/lib/friendly_id/slugged.rb:304:in `set_slug'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:432:in `block in make_lambda'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:164:in `call'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:164:in `block in halting'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:504:in `call'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:504:in `block in call'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:504:in `each'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:504:in `call'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:92:in `_run_callbacks'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/callbacks.rb:776:in `_run_validation_callbacks'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activemodel-4.2.2/lib/active_model/validations/callbacks.rb:113:in `run_validations!'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activemodel-4.2.2/lib/active_model/validations.rb:334:in `valid?'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/validations.rb:58:in `valid?'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.2/lib/active_record/validations.rb:83:in `perform_validations'
... 20 levels...
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/console.rb:9:in `start'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/railties-4.2.2/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `require'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `require'
    from /Users/hellomello/sites/project_app/bin/rails:8:in `<top (required)>'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `block in load'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/hellomello/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
    from /Users/hellomello/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/hellomello/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'2.2.1 :042 > 
Community
  • 1
  • 1
hellomello
  • 8,219
  • 39
  • 151
  • 297

1 Answers1

0
NameError: uninitialized constant Tag

It means that Tag class was not loaded in the environment.

Try to use the name scoped name like: ActsAsTaggableOn::Tag (like the link you posted) rather than Tag only. Also, see if you need to require the act_as_taggable_on.rb file somewhere so that it loads properly. This error happens when the class doesn't load properly.

Did you add the new class to the /lib/ directory? Then, check (or add) if you have something like this in your application.rb file:

config.autoload_paths += %W(#{config.root}/lib)
K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110