练习50 :: http://ruby.learncodethehardway.org/book/ex50.html(使用sinatra运行hello world时出错)

时间:2013-05-20 08:49:42

标签: ruby sinatra

我正在尝试ex:50 of learning Ruby the hard way ..这涉及使用' sinatra'创建hello_world应用程序。 我得到的错误如下:

 ruby lib/gothonweb.rb
    lib/gothonweb.rb:5:in `<module:Gothonweb>': undefined method `get' for Gothonweb:Module             (NoMethodError)
    from lib/gothonweb.rb:4:in `<main>'

1 个答案:

答案 0 :(得分:2)

这不是你做过的事情,给出的代码不起作用:

require_relative "gothonweb/version"
require "sinatra"

module Gothonweb
  get '/' do
    greeting = "Hello, World!"
    return greeting
  end
end

这不会起作用,因为它包含在一个模块中。试试这个:

require_relative "gothonweb/version"
require "sinatra"

get '/' do
  greeting = "Hello, World!"
  greeting # there's no need for the return here,
           # the last expression is the return value
end
相关问题