Ruby:如何将变量从服务器传递到索引?

标签 ruby post get sinatra erb

something = "0"

get "/" do
   erb :index, :locals => something
end

当我这样做并转到本地主机时,它说“0”的未定义方法“键”:字符串。我正在使用西纳特拉。如何将变量从服务器传递到索引?

最佳答案

你已经完成了一半,你只需要让something成为一个对象。

get "/" do
   erb :index, :locals => {:something => 0}
end

然后在你的索引中使用它:

Something: <%= something %>

关于Ruby:如何将变量从服务器传递到索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31660381/

相关文章:

ruby-on-rails - RSpec 无法显示消息

javascript - 如何通过 Ajax 将表单数据提交到我的 Ruby Controller ?

django - 避免在 django post 方法中使用 csrf token

ios - Zend 1.10 'isPost' 在 Af Networking 2.2 发布到它时返回 false

javascript - Angular HTTP 'get' 请求 304 错误

Ruby 2.3.8 在 mint 中使用 rbenv 安装错误 |不常见.mk :203: recipe for target 'build-ext' failed

ruby - 将 nil 强制转换为数字

c# - 使用 html 助手时没有发布值

php - 如何在我的示例中使用 urlencode()?

c++ - 使用wininet与服务器交换数据