views:

476

answers:

2

I have written this generator code but it returns 'can't convert nil into String' when I call m.directory inside the manifest. Anyone know what had happened?

class AuthGenerator < Rails::Generator::NamedBase
  attr_reader :user_class_name
  def initialize(runtime_args, runtime_options={})
    @user_class_name="User"
    @controller_class_name="AccountController"
    @user_class_file_name="#{@user_class_name}.rb"
    @controller_class_file_name="#{@controller_class_name}.rb"
  end

  def manifest
    record do |m|
      m.class_collisions @controller_class_name, @user_class

      puts @user_class_name
      m.directory File.join('app/models', @user_class_name)


    end
  end

end

+1  A: 

Where is it choking? Please post the full error. You can see the source of the directory method here.

Plus, you probably just want

m.directory File.join('app/models')

Having an app/models/user directory for your generated code is not standard -- unless you're intending namespacing, which it doesn't look like.

Ian Terrell
A: 

Your initialize method needs a call to super.

Lachlan Sylvester