2012-08-25 2 views
0

저는 IDE RubyMine을 사용하여 웹 기반 Ruby 프로그램을 작성하고 있습니다.RubyMine을 사용하여 웹 기반 Ruby 프로그램 만들기

나는 classses의 몇 가지있다 :

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 

나는에

http://localhost:3000 

를 찾아

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 

course_modules.rb: 파이어 폭스, 나는 오류 메시지를 표시하는 것 웹 페이지를 받고 있어요, 내 웹 페이지를 보려면 :

오류 메시지가 말한다 :

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 

사람이 왜 표시하는 웹 페이지를받지 못했습니다 알고 있나요 내 웹 응용 프로그램? 이 권리를 어떻게 넣을 수 있습니까?

답변

0
class application_controller < ActionController::Base 

class ApplicationController < ActionController::Base 

application_controller 루비에서 잘못된 클래스 이름이어야합니다. 당신은 제대로라는 이름의 클래스로

➜ ~ 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>' 

을 실행하여 단순히 IRB이를 테스트 할 수 있습니다 (A 대신 a), 그러한 문제

➜ ~ irb 
irb(main):001:0> class A;end 
=> nil 
irb(main):002:0> 
없다
관련 문제