sinatra

Is Sinatra multi threaded?

回眸只為那壹抹淺笑 提交于 2019-12-17 08:12:10
问题 Is Sinatra multi-threaded? I read else where that "sinatra is multi-threaded by default", what does that imply? Consider this example get "/multithread" do t1 = Thread.new{ puts "sleeping for 10 sec" sleep 10 # Actually make a call to Third party API using HTTP NET or whatever. } t1.join "multi thread" end get "/dummy" do "dummy" end If I access "/multithread" and "/dummy" subsequently in another tab or browser then nothing can be served(in this case for 10 seconds) till "/multithread"

Separate REST JSON API server and client? [closed]

孤人 提交于 2019-12-17 05:15:12
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I'm about to create a bunch of web apps from scratch. (See http://50pop.com/code for overview.) I'd like for them to be able to be accessed from many different clients: front-end websites, smartphone apps, backend webservices, etc. So I really want a JSON REST API for each

Sinatra + omniauth + Android, advice sought

北战南征 提交于 2019-12-14 04:01:03
问题 I'm developing a Sinatra app for which I'd like to use OmniAuth. So far, I have something similar to this for the web app: http://codebiff.com/omniauth-with-sinatra I'd like the web app to be usable via Android phones which would use an API, authenticating by means of a token. The development of an API seems to be covered nicely here: Sinatra - API - Authentication What is not clear is now I might arrange the login procedure. Presumably it would be along these lines: User selects what service

How do I store/access/update a thread-safe variable in an Sinatra app (+unicorn)?

删除回忆录丶 提交于 2019-12-14 03:24:41
问题 I want to store and update an Enum in an thread-safe way in my sinatra app. I use unicorn. I tried the following: #!/usr/bin/ruby require 'sinatra' $locked = false $num = 0 class App < Sinatra::Base before do while $locked do end $locked = true end after do $locked = false end get "/wait" do sleep 10 $num += 1 erb :display end get "/winner" do $num += 1 erb :display end end The view just shows $num ;) I started the app with unicorn (4 workers) and visited http://localhost:8080/winner with my

Sinatra/Rack `ERROR URI::InvalidURIError: bad URI(is not URI?)` on redirect

我怕爱的太早我们不能终老 提交于 2019-12-14 02:33:46
问题 I've just started my first Sinatra project, a simple TV-show management web app, and wanted to have beautiful URLs. So when a user types in the search box and submits, I don't want to have a /?search=foobar -style URL and want do redirect them to /search/foobar . This also enables me to separate the get '/search/:name route from the main get '/' route. I've implemented the redirect using a before filter and properly escaped the params[] variable: before do if params.has_key? 'search' redirect

Serve HTML files stored on S3 on a Rack app

痴心易碎 提交于 2019-12-13 19:04:09
问题 Say I have some HTML documents stored on S3 likes this: http://alan.aws-s3-bla-bla.com/posts/1.html http://alan.aws-s3-bla-bla.com/posts/2.html http://alan.aws-s3-bla-bla.com/posts/3.html http://alan.aws-s3-bla-bla.com/posts/1/comments/1.html http://alan.aws-s3-bla-bla.com/posts/1/comments/2.html http://alan.aws-s3-bla-bla.com/posts/1/comments/3.html etc, etc I'd like to serve these with a Rack (preferably Sinatra) application, mapping the following routes: get "/posts/:id" do render "http:/

Sinatra SASS custom directory

北城以北 提交于 2019-12-13 16:50:21
问题 How to config Sinatra to use custom SCSS directory? I tried the following solution, but this didn't work for me. class SassEngine < Sinatra::Base set :views, File.dirname(__FILE__) + '/sass' get '/sass/*.scss' do filename = params[:splat].first sass filename.to_sym end end 回答1: Actually the official documentation has a section exactly for this use case. Sinatra Documentation - Looking up Templates To make it easier here is the code (taken from the documentation): set :views, :sass => 'views

RestKit - Post object and update its attributes

核能气质少年 提交于 2019-12-13 14:52:59
问题 I have a small app using RestKit with a Sinatra-backed server. When I post a user object to the server, the server successfully saves the user and responds with a json representation of the newly created user. Here's the code to create a user on the client: User *currentUser = [User currentUser]; currentUser.email = @"jacob@mail.com"; currentUser.firstName = @"Jacob"; currentUser.lastName = @"Morris"; currentUser.phone = @"2088956709"; currentUser.deviceId = @"MY-DEVICE-ID"; currentUser

Ruby Datamapper count not working

落爺英雄遲暮 提交于 2019-12-13 14:25:36
问题 From irb when I do: Router.all(:email=>"blake@gmail.com") I get a list of all the routers associated with that email. But when I do: Router.count(:email=>"blake@gmail.com") I always get 0 I've also looked at this question: Ruby Datamapper .count always returns 0 but I still don't know why it isn't working. -- Update #1 -- Here is the output of the Router.all command. As you can see I get results back. 1.9.3-p362 :003 > Router.all(:email=>"blake@gmail.com") => [#<Router @id=8 @email="blake

Stylesheet not applying to sinatra erb views

我怕爱的太早我们不能终老 提交于 2019-12-13 14:09:21
问题 My stylesheet is applying to some elements of my app and not others, and I'm not sure why. Here is my document structure: Currently, the stylesheet is being applied to index.erb and contacts.erb, but not the others in the tree, and I'm not sure why. In my layout I've specified: <link rel="stylesheet" type="text/css" href="style.css"> Any ideas? 回答1: You are using a relative reference to your stylesheet, so the browser will request it relative to the current url. This means for / and /contacts