Создание веб-программы на Ruby с использованием RubyMine

Я пишу веб-программу на Ruby, используя IDE RubyMine.

У меня есть пара классов:

application_controller.rb:

class application_controller < ActionController::Base
# To change this template use File | Settings | File Templates.
# require './course_modules.rb'
def initialize
  self.class.main_menu
end

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

def self.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.remove_module
    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

а также course_modules.rb:

class CourseModulesController < ActionController::Base
# To change this template use File | Settings | File Templates.
@@moduleScheme = nil
@@moduleYear = nil
#@moduleTitle = ""
@noOfModulesInScheme = 0

$schemes = {}
$module_ID = 0
$module_exists = false

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
  # module_exists = false
  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"
    elsif
    scheme_exists == true
      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
      # puts "Module #{module_name.chop} has been added to #{scheme_name.chop}"

      # 22/08/2012 at 14:15 Now need to read in each module's unique identifier and year it belongs to
      print "Enter module ID: "
      $module_ID =gets
      $schemes[scheme_name.chop].include?($module_ID.chop) ? true : $schemes[scheme_name.chop] << $module_ID.chop
      $schemes.has_key?($module_ID.chop) ? module_exists = true : module_exists = false

      print "Enter the academic year to which the module belongs: "
      module_year = gets
      $schemes[scheme_name.chop].include?(module_year.chop) ? true : $schemes[scheme_name.chop] << module_year.chop

      if !$module_exists
        $schemes[$module_ID.chop] = []
        puts "Module #{$module_ID.chop} : #{module_name.chop} has been added to #{scheme_name.chop} for the year #{module_year}"
      elsif
      $module_exists == true
        puts "A module with this ID has already been added to the scheme, please check if the module already exists, or choose another ID "
      else
        #  puts "Module #{module_name.chop}, #{module_ID.chop} has been added to #{scheme_name.chop} for the year #{module_year}"
      end

      # puts "Module #{module_name.chop}, #{module_ID.chop} has been added to #{scheme_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
    scheme_exists = $schemes.has_key? (scheme_name.chop)

    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
def self.remove_module

  print "Which scheme would you like to remove a module from? "
  scheme_name = gets
  #$schemes.has_key?(scheme_name.chop) ? scheme_exists = true : scheme_exists = false
  scheme_exists = $schemes.has_key? (scheme_name.chop)

  if !scheme_exists
    $schemes[scheme_name.chop] = []
    puts "Scheme #{scheme_name.chop} doesn't exist"
  else
    scheme_exists = true
    puts "Which module would you like to remove from #{scheme_name.chop}?"
    $module_ID = gets
    if !$module_exists
      $schemes[$module_ID.chop] = []
      puts "Module #{$module_ID.chop} : does not exist in #{scheme_name.chop} "
    else
      module_exists = true
      puts "Module #{$module_ID.chop} has been removed from #{scheme_name.chop} "
      #  puts "Module #{module_name.chop}, #{module_ID.chop} has been added to #{scheme_name.chop} for the year #{module_year}"
    end
  end

 end

end

Когда я просматриваю

http://localhost:3000 

в Firefox, чтобы просмотреть мою веб-страницу, я получаю веб-страницу с сообщением об ошибке:

Сообщение об ошибке говорит:

SyntaxError in ApplicationController#main_menu

(Filepath)/application_controller.rb:1: class/module name must be CONSTANT
class application_controller < ActionController::Base

Rails.root: (Filepath)/CourseManagementSystem

Кто-нибудь знает, почему я не получаю веб-страницу с моим веб-приложением? Как я могу это исправить?

1 ответ

class application_controller < ActionController::Base

Это должно быть

class ApplicationController < ActionController::Base

application_controller недопустимое имя класса в ruby. Вы можете проверить это просто в IRB, запустив

➜  ~  irb
irb(main):001:0> class a;end
SyntaxError: (irb):1: class/module name must be CONSTANT
class a;end
    ^
    from /Users/deefour/.rbenv/versions/1.9.3-p125/bin/irb:12:in `<main>'

С правильно названным классом ( A вместо a ) такой проблемы нет

➜  ~  irb
irb(main):001:0> class A;end
=> nil
irb(main):002:0> 
Другие вопросы по тегам