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

  • Home
  • SEARCH
  • 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 8414917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:17:39+00:00 2026-06-10T01:17:39+00:00

I am writing a program using Ruby on Rails to allow users to manage

  • 0

I am writing a program using Ruby on Rails to allow users to manage University courses, their modules, and the students enrolled on them.

Currently, I have two classes: Application.rb and CourseModules.rb:

Application.rb is the class that I am using to interface with the user- it currently looks like this:

Code:

class Application
# To change this template use File | Settings | File Templates.
require './courseModules.rb'
def initialize
  main_menu
end

=begin
  def navigateTo(what)
  what.new(v).display
  mainMenu
  end
=end

def main_menu
  puts "What would you like to do?
      1: Add module to a scheme
      2: Remove module from a scheme
      3: Query modules
      4: Modify module
      5: Register a student on a scheme
      6: Remove a student from a scheme
      7: Register a student on a module
      8: Remove a student from a module"
  case gets.strip
    when "1"
      CourseModules.add_module
    when "2"
      CourseModules.removeModuleFromScheme
    when "3"
      navigateTo CourseModules
    when "4"
      navigateTo CourseModules
    when "5"
      navigateTo Student
    when "6"
      navigateTo Student
    when "7"
      navigateTo Student
    end
  end
  Application.new
end

and CourseModules.rb is where I am doing all of the work- it currently looks like this:

Code:

class CourseModules
# To change this template use File | Settings | File Templates.
   @@moduleScheme = nil
   @@moduleYear = nil
   #@moduleTitle = ""
   @noOfModulesInScheme = 0

   def self.moduleYear
     @@moduleYear
   end

   def initialize(v)
     @val = v
   end
   # Set and get the @val object value
   def set (v)
     @val = v
   end
   def get
     return @val
   end


# Attempt at add_module method on 21/08/2012 at 16:30
def self.add_module
  schemes = {}
  scheme_exists = false
  add_another_scheme = true
  add_another_module = true

  while add_another_scheme
    print "Enter scheme name: "
    scheme_name = gets
    schemes.has_key?(scheme_name.chop) ? scheme_exists = true : scheme_exists = false

   if !scheme_exists
     schemes[scheme_name.chop] = []
     puts "Scheme #{scheme_name.chop} has been added to the system"
   else
     scheme_exists = false
     puts "This scheme has already been added"
   end

   while add_another_module
     print "Enter module name: "
     module_name = gets
     schemes[scheme_name.chop].include?(module_name.chop) ? true : schemes[scheme_name.chop] << module_name.chop
     print "Add another module? "
     ask_if_user_wants_to_add_another_module = gets
     if(ask_if_user_wants_to_add_another_module.chop == "y" or ask_if_user_wants_to_add_another_module == "yes")
      add_another_scheme = false
     else if(ask_if_user_wants_to_add_another_module.chop != "y" or ask_if_user_wants_to_add_another_module != "yes")
       Application.main_menu
          end
   end

 end

 print "Add another scheme? "
 ask_if_user_wants_to_add_another_scheme = gets
 if !(ask_if_user_wants_to_add_another_scheme.chop == "y" or ask_if_user_wants_to_add_another_scheme.chop == "yes")
   add_another_scheme = false
 end
 puts @schemes

end

 while add_another_module
   print "Enter scheme name: "
   scheme_name = gets
   schemes.has_key?(scheme_name.chop) ? scheme_exists = true : scheme_exists = false

   if !scheme_exists
     print "Enter module name: "
     module_name = gets
     schemes[scheme_name.chop] = module_name.chop
     puts "Scheme #{scheme_name.chop} with module #{module_name} has been added to the system"
   else
     scheme_exists = false
     puts "This scheme has already been added"
     puts "Enter module name: "
     module_name = gets
     schemes[scheme_name.chop] = module_name.chop
     puts "Scheme #{scheme_name.chop} with module #{module_name} has been added to the system"
   end

   print "Add another module? "
   ask_if_user_wants_to_add_another_module = gets
   if !(ask_if_user_wants_to_add_another_module.chop == "y" or ask_if_user_wants_to_add_another_module.chop == "yes")
     add_another_module = false
   end
 end
 puts schemes
end

end

At present, when I run the program from Application.rb, I am presented with the menu, and I choose option 1: “Add module to a scheme”

I am then asked to enter a scheme name, which I do, and a line appears telling me that the scheme has been added to the system.

Next, I am asked to enter the name of the module, which I do, and am then asked if I’d like to enter another module. If I type ‘y’ or ‘yes’, I am allowed to enter the name of another module.
However, if I type ‘n’ or anything other than ‘y’ or ‘yes’, the program crashes and I get a few errors in the console.

The first of these errors says:

in add_module': undefined methodmain_menu’ for Application:Class (NoMethodError)

on the line:

Application.main_menu

in the

def self.add_module

method in my CourseModules.rb class.

What should happen is that when the user enters ‘n’ or anything other than ‘y’ or ‘yes’ when asked if they’d like to add another module, they should be taken back the program main menu.

Does anyone have any idea what I’m doing wrong here? How can I put it right?

  • 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-06-10T01:17:40+00:00Added an answer on June 10, 2026 at 1:17 am

    It looks like you are trying to call a class method with Application.main_menu when it is defined as an instance method on the Application class which is why you are getting an undefined_method. Try adding self to the main_menu method definition.

    class Application
      def self.main_menu
        ....
      end
    end
    

    Fix based on your comments:

    You will need to modify the initialize method as well. You can do so by changing it to this

    class Application
      def initialize
        self.class.main_menu
      end
    
      ...
    
    end
    

    By adding just self before main_menu in the initialize method you are just telling initialize that you want to initialize a new method when you create a new Application class. In order to tell initialize that you want this method to be a class method you need to pass in the class as well. I hope this makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Ruby program to manage courses run at a university, the modules
I'm writing a program in Ruby for the first time (I'm using RubyMine as
I'm writing a ruby program that will be using threads to do some work.
I'm writing a course management program in Ruby, to assist with managing courses at
I am currently writing a program using Weka that builds a model (using one
I am writing a program using RedGate SQL Compare that syncs data between nodes
I am writing a program using Delphi 2006 and storing data in XML files
I'm writing a program using C++ and the MySQL C API (version 5.1.31 ubuntu2).
I'm writing a coprocess program using pipe. It works fine when the child read
I am writing an application program using swing. I need to exit from the

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.