https://github.com/oscardelben/firebase-ruby
如何在方法中使用firebase而不是在本地使用firebase,如示例所示?例如:@firebase
,请参见以下网址:
http://bpaste.net/show/501b6a67c8d4
或 -
require 'sinatra'
require 'firebase'
require 'bundler'
Bundler.require
# Configure database
configure do
@base_uri = 'https://veriyo.firebaseio.com/'
@firebase = Firebase::Client.new(@base_uri)
end
# Display homepage
get '/' do
erb :index
end
post '/search' do
@username = params["username"]
redirect to("/user/#{@username}")
end
get '/user/:username' do
response = @firebase.push("todos", { :name => @username })
'hello'
end
@ firebase变量的属性无法访问 - #<NoMethodError: undefined method
push'代表nil:NilClass&gt;`
答案 0 :(得分:4)
将它们设置为常量:
FB_Base_uri = 'https://veriyo.firebaseio.com/'
FB_Firebase = Firebase::Client.new(FB_Base_uri)