Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4337324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:55:43+00:00 2026-05-21T10:55:43+00:00

Might sound like a simple question, but I’m stumped. I’ve created a gem that

  • 0

Might sound like a simple question, but I’m stumped.

I’ve created a gem that essentially contains a generator.

It contains the following structure:

lib
 - generators
    - my_generator
          my_generator_generator.rb (see below)
          - templates
             my_template_files...     
 - my_generator.rb (empty file)
test
 -test files
GemFile
etc..

However when I add this Gem to my gem file and run rails g, it’s not listed. Is there any additional config that I need to do?

My generator roughly looks like this…

class MyGeneratorGenerator < Rails::Generators::NamedBase
      source_root File.expand_path('../templates', __FILE__)
      generator code....
 end

The strange thing is, it works in Cygwin, but not in Ubuntu…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:55:44+00:00Added an answer on May 21, 2026 at 10:55 am

    This took a little bit for me to figure out, but I’ve run into the same problem. Here is how I fixed it.

    Tree structure looks like this:

    lib
      - generators
        - gemname
          install_generator.rb
          - templates
            (template files)
    

    Here’s the code for install_generator.rb

    #lib/generators/gemname/install_generator.rb
    require 'rails/generators'
    module Gemname
      class InstallGenerator < Rails::Generators::Base
        desc "Some description of my generator here"
    
        # Commandline options can be defined here using Thor-like options:
        class_option :my_opt, :type => :boolean, :default => false, :desc => "My Option"
    
        # I can later access that option using:
        # options[:my_opt]
    
    
        def self.source_root
          @source_root ||= File.join(File.dirname(__FILE__), 'templates')
        end
    
        # Generator Code. Remember this is just suped-up Thor so methods are executed in order
    
    
      end
    end
    

    When I run
    rails g

    I see:

    Gemname
       gemname:install
    

    Some other things you may need to setup:

    #lib/gemname.rb
    module Gemname
      require 'gemname/engine' if defined?(Rails)
      # any additional requires
    end
    

    and

    #/lib/gemname/engine.rb
    require 'rails'
    module Gemname
      class Engine < Rails::Engine
      end
    end
    

    Some good references I’ve found on this are:

    • http://textmate.rubyforge.org/thor/Thor.html (take a look at the modules, especially Thor::Actions)
    • http://api.rubyonrails.org/classes/Rails/Generators/Base.html
    • http://api.rubyonrails.org/classes/Rails/Generators/Actions.html
    • https://github.com/wycats/thor/blob/master/README.md
    • http://www.themodestrubyist.com/2010/03/16/rails-3-plugins—part-3—rake-tasks-generators-initializers-oh-my/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might sound like a little bit of a crazy question, but how can
This might sound like a stupid question, but google didn't help me. Is there
This might sound like a reaaaally dumb question but... why do browsers have a
This might sound like a stupid question but ... will WPF stop running in
Ok, this might sound like a silly question, but I'm having all sorts of
This might sound like a silly question but how would I make this code
This might sound like a trivial question to a lot of people, but since
this might sound like a daft question but I can't seem to find a
This might sound a bit of an odd question but I know what I
I know this question might sound a little cheesy but this is the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.