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/