我正在尝试 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>'
最佳答案
这不是您所做的事情,给出的代码不起作用:
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
关于ruby - 练习 50::http://ruby.learncodethehardway.org/book/ex50.html(使用 sinatra 运行 hello world 时出错”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16645762/