Firebase Ruby Global Variable

https://github.com/oscardelben/firebase-ruby

How can I use firebase for different methods and not locally as shown in the examples? Example: @firebase

see Paste at - http://bpaste.net/show/501b6a67c8d4

or -

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 variable attributes not available there - #<NoMethodError: undefined method

push 'for nil: NilClass> `

+3


source to share


1 answer


Set them as constants:



FB_Base_uri = 'https://veriyo.firebaseio.com/'
FB_Firebase = Firebase::Client.new(FB_Base_uri)

      

+4


source







All Articles