SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    `load_missing_constant': uninitialized constant Rails::Generator (NameError)

    Hello,
    I'm probably missing something pretty basic here as a rails newbie but I'm trying to write a plugin and I am trying to get my generator to work.

    I am trying to call the manifest method in my vendor/plugins/media_module/generators/media_module_generator.rb from my vendor/plugins/media_module/init.rb.

    here's the code in vendor/plugins/media_module/init.rb:
    Code:
    require File.join(File.dirname(__FILE__), '/generators/media_module_generator')
    media_mod_generatore = MediaModuleGenerator.new 
    media_mod_generatore::manifest()
    and here's my code in vendor/plugins/media_module/generators/media_module_generator.rb:
    Code:
    class MediaModuleGenerator < Rails::Generator::NamedBase
      def manifest
        record do |m|
          m.file "media_controller.rb", "app/controllers/media_controller.rb"
          m.file "media.rb", "app/models/media.rb"
        end
      end
    end
    When I restart my server I get this:
    `load_missing_constant': uninitialized constant Rails::Generator (NameError)

    Thanks,
    Clem C

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,182
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    Using the monkey see monkey do approach, the shovell app's vendor files are
    acts_as_taggable_migration_generator.rb
    Code Ruby:
    class ActsAsTaggableMigrationGenerator < Rails::Generator::Base 
      def manifest 
        record do |m| 
          m.migration_template 'migration.rb', 'db/migrate' 
        end 
      end
     
      def file_name
        "acts_as_taggable_migration"
      end
    end
    and
    init.rb
    Code Ruby:
    require File.dirname(__FILE__) + '/lib/acts_as_taggable'
    where the lib folder contains several files.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just don't get it - I pretty much am following every example I've seen to a tee and I keep getting the same error.

    I tried moving the media_module_generator.rb to /lib/media_module_generator.rb and I get the same exact error.

    Grrrrrrrrrr

    Thanks for the help though!

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,182
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    The full contents are

    shovell/vendor/plugins/acts_as_taggable_on_steroids/
    .........................CHANGELOG
    .........................init.rb
    .........................MIT-LICENSE
    .........................Rakefile
    .........................README
    ......................../generators/acts_as_taggable_migration/
    .................................................acts_as_taggable_migration_generator.rb
    ................................................../templates/
    ................................................................migration.rb
    ......................../lib/
    ..............................acts_as_taggable.rb
    ..............................tag.rb
    ..............................tag_counts_extension.rb
    ..............................tag_list.rb
    ..............................tagging.rb
    ..............................tags_helper.rb
    ......................../test/
    .................................abstract_unit.rb
    .................................acts_as_taggable_test.rb
    .................................database.yml
    .................................schema.rb
    .................................tag_list_test.rb
    .................................tag_test.rb
    .................................tagging_test.rb
    .................................tags_helper_test.rb
    ................................/fixtures/
    ............................................magazine.rb
    ............................................magazines.yml
    ............................................photo.rb
    ............................................photos.yml
    ............................................post.rb
    ............................................posts.yml
    ............................................special_post.rb
    ............................................subscription.rb
    ............................................subscriptions.yml
    ............................................taggings.yml
    ............................................tags.yml
    ............................................user.rb
    ............................................users.yml

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You know - I really think that a generator class can't be required and instantiated in init.rb. I was hoping that as I developed this plugin, everytime I started the server would fire off the generator::manifest method so I could make sure I was always up to date w/ the generated files.

    Is my logic completely whacked?

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shameless boot! This is driving me crazy!

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,182
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    I just tried the code described in http://www.sitepoint.com/blogs/2008/...ite-a-plug-in/
    and it worked as expected
    Code:
    C:....>rails blabber
    ........
    C:....>cd blabber
    C:....\blabber>ruby script/generate plugin acts_as_blabbermouth
    ........
    C:....\blabber>ruby script/generate model quote
    ........
    C:....\blabber>ruby script/console
    Loading development environment (Rails 2.1.0)
    >> Quote.quote_me
    => "Drive-in banks were established so most of the cars today could see their real owners. -E. Joseph Cossman"
    >> Quote.quote_me
    => "What we anticipate seldom occurs; what we least expected generally happens. -Benjamin Disraeli"
    >> Quote.quote_me
    => "What we anticipate seldom occurs; what we least expected generally happens. -Benjamin Disraeli"
    >> Quote.quote_me
    => "Every child is an artist. The problem is how to remain an artist once he grows up. -Pablo Picasso"
    >>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •