Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase global variable Ruby

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

How do I use firebase across methods and not locally as shown in the examples? Ex: @firebase, See the 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

The @firebase variable's attributes aren't accessible there -- #<NoMethodError: undefined methodpush' for nil:NilClass>`

like image 960
Tejas Manohar Avatar asked Feb 14 '26 05:02

Tejas Manohar


1 Answers

Set them as constants:

FB_Base_uri = 'https://veriyo.firebaseio.com/'
FB_Firebase = Firebase::Client.new(FB_Base_uri)
like image 184
Joel Brewer Avatar answered Feb 15 '26 18:02

Joel Brewer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!