sinatra

Sessions in Sinatra using Facebook authentication

一个人想着一个人 提交于 2019-12-12 09:13:37
问题 I'm very new to ruby & Sinatra and I have a basic question: The app I'm trying to build will use Facebook as it's sole method of authenticating users into the app. I want to store a local users table which will contain only the facebook uid along with some user preferences. I have looked at a couple of gems which allow me to authenticate against the facebook API, however I am unsure how to control sessions within my application once I have established the user is valid. I have been using the

generating css file from new sass format (scss) with sinatra and haml

蹲街弑〆低调 提交于 2019-12-12 08:52:09
问题 I am writing a sinatra app with haml and sass. When I try to link in the stylesheet with a scss extension located in my views folder I get the following error: NoMethodError at /nav.css undefined method `scss' Here is my get method get '/nav.css' do content_type 'text/css', :charset => 'utf-8' scss :nav end I have only gotten this to work when I switch to the older sass syntax. I also have to change the nav.scss to nav.sass and the get method to sass :nav I have also tried just having sass

Rack Session Cookie and Sinatra - setting and accessing data

こ雲淡風輕ζ 提交于 2019-12-12 08:35:37
问题 I was using Rack Session Pool, however my users would get kicked off one webserver thread onto another making the session data expire. I started toying around with just enable :sessions in Sinatra, however I am unable to use that because I have mutliple apps using Sinatra (same key it appears to be using - not sure if this is because its the same host or not) So since my apps would break each other, I now am trying Rack Session Cookie and setting the variables (same thing as enable :sessions,

Environment variables locally and Heroku

£可爱£侵袭症+ 提交于 2019-12-12 08:20:53
问题 I have a sinatra app in which i have a yml file to set environment variables, i call them using this method module MyConfig def config environment = ENV["RACK_ENV"] || "development" YAML.load_file("./config/config.yml")[environment] end end so when i want to use a variable i do this for example aws_access_key_id = config['aws_access_key'] I have a .gitignore file that ignores config.yml when pushing to github for example.So when I push to heroku these environment variables will not be

Handling event-stream connections in a Sinatra app

房东的猫 提交于 2019-12-12 08:18:18
问题 There is a great example of a chat app using Server-Sent Events by Konstantin Haase. I am trying to run it and have a problem with callbacks (I use Sinatra 1.3.2 and browse with Chrome 16). They simply do not run (e.g. after page reload), and therefore the number of connections is growing. Also, connection is closed in 30-60 sec unless one sets a periodic timer to send empty data, as suggested by Konstantin elsewhere. Can you replicate it? If yes, is it possible to fix these issues somehow?

How does sinatra start the server?

亡梦爱人 提交于 2019-12-12 06:46:56
问题 I have been trying to delve into how sinatra works, and most recently I've been trying to figure out how sinatra starts the server after processing the routes, when it is required at the top of the file. I was looking at this tutorial and they end with an example app looking like this (their version of sinatra is called nancy): # app.rb # run with `ruby app.rb` require "./nancy" get "/" do "Hey there!" end Rack::Handler::WEBrick.run Nancy::Application, Port: 9292 I am wondering how you are

ruby loop through data returned by API call

蓝咒 提交于 2019-12-12 04:58:57
问题 I am working with ruby and sinatra. Using the Plivo api, I want to access the returned data, iterate through it and extract and print all the instances of some of the elements and print them out as HTML on my web page. my ruby code is: user_key = 'my_key' params = { 'account' => user_key } response = p.get_cdrs(params) obj = response.last.to_json which gets the following returned in the Firebug console: { "api_id":"c59f2008-5baf-11e3-bbb2-22000ac522d1", "meta":{ "limit":20, "next":"/v1

Sinatra Logger for Web Service Errors

夙愿已清 提交于 2019-12-12 04:58:26
问题 I am using Sinatra 1.3 and it's a Sinatra::Application . I have a method that fetches a web service. I want to log when this service has succeed and what it has failed as it runs in the background (cron job) def fetch_some_web_service begin #if successful log.info "Success" rescue SocketError => e log.info "Failed" end end I can't seem to use the Sinatra logger instance . It's generating errors for me and I'm assuming it's doing this because I'm logging in a method and not within a route?

How to test background process in RSpec?

痴心易碎 提交于 2019-12-12 04:33:37
问题 Found this simple way to run a separate process in Sinatra: Run background process in Sinatra get '/start_process' @@pid = Process.spawn('external_command_to_run') end How would you test this in RSpec? Ruby 1.9.3. 回答1: Extract a class which does the background processing and unit-test it. Then test expectation that your action invokes method on this class Some "pseudocode": before do MyWorker.should_receive(:perform) end specify { get :something } 来源: https://stackoverflow.com/questions

Rake tasks won't run inside of my sinatra app

帅比萌擦擦* 提交于 2019-12-12 04:18:25
问题 I have a sinatra app with a Rakefile.rake and server.rb file. In the server.rb file I have get '/' do rake :test end the app loads up but crashes when I load localhost:4567/ and says undefined method 'rake' for sinatra application. I try and require the file by using require '/home/user/project/Rakefile' and I also try Rakefile.rake but both give me an error that reads "require cannot load such file." I'm using Ubuntu. I'm not sure why sinatra can't load the rakefile, but when I run rake test