sinatra

What's the fastest way for a true sinatra(ruby/rack) after_filter?

回眸只為那壹抹淺笑 提交于 2019-12-05 04:18:19
Okay it's a simple task. After I render html to the client I want to execute a db call with information from the request. I am using sinatra because it's a lightweight microframework, but really i up for anything in ruby, if it's faster/easier(Rack?). I just want to get the url and redirect the client somewhere else based on the url. So how does one go about with rack/sinatra a real after_filter. And by after_filter I mean after response is sent to the client. Or is that just not dooable without threads? I forked sinatra and added after filters, but there is no way to flush the response, even

Empty, uneditable pg_hba.conf file

独自空忆成欢 提交于 2019-12-05 02:42:20
I am trying to connect my Sinatra app to PostgreSQL database with this tutorial: http://samuelstern.wordpress.com/2012/11/28/making-a-simple-database-driven-website-with-sinatra-and-heroku/ . Everything goes fine until I try to execute: rake:db migrate then I get this error: rake aborted! PG::ConnectionBad: fe_sendauth: no password supplied It seems like I should change my permissions in pg_hba.conf file, but, opening it, I see nothing. And, if I try to write something into it, it says it's " readonly ". Am I on the right way of getting rid of the error and where to go next? edit: actually, if

Simple and Ideal Logging in Sinatra

删除回忆录丶 提交于 2019-12-05 01:51:29
问题 I went through few blogs and sites which gave me some information about how to log in sinatra but didnt work for my app and also i went through a gem called sinatra-logger didnt tried it, wanted to know ideal and simple way to "log" in sinatra. Like we do logger.info for rails. The code which i tried and didnt work is from the following site link and also some of SO links were too pointing to the same approach used in the link above. configure do LOGGER = Logger.new("sinatra.log") end helpers

Asynchronously iterating over the response of a request using Thin and Sinatra

空扰寡人 提交于 2019-12-05 01:24:29
问题 If your response in Sinatra returns an 'eachable' object, Sinatra's event loop will 'each' your result and yield the results in a streaming fashion as the HTTP response. However, if there are concurrent requests to Sinatra, it will iterate through all the elements of one response before handling another request. If we have a cursor to the results of some DB query, that means we have to wait for all the data to be available before handling a concurrent query. I've looked at the async-sinatra

Sinatra rack middleware hijacks '/' root url

天涯浪子 提交于 2019-12-04 22:23:36
I'm trying to use a Sinatra app as middleware in my Rails app. I've tested a basic Sinatra app in the /lib folder of the Rails app, use d the middleware and set a route. That worked fine. What I want to be able to do is extract the Sinatra app and include it as a gem. That way I can run the Sinatra app independently, or use it in multiple Rails apps. Sinatra App # myrackapp/lib/myrackapp.rb module Myrackapp class Application < Sinatra::Base set :root, File.dirname(__FILE__) get "/" do "Rack Home" end get '/rackroute' do "Hello, Rack Page" end end end Myrackapp also has a gemspec – nothing

undefined method `run' for main:Object (NoMethodError) Sinatra

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 22:04:23
问题 require 'sinatra/base' class Foo < Sinatra::Base get('/foo') { 'foo' } end class Bar < Sinatra::Base get('/bar') { 'bar' } end run Rack::Cascade, [Foo, Bar] I just can't guess what is wrong with this code. When I ran: ruby server.rb, it throws an error 回答1: First of all, the last line should read run Rack::Cascade.new [Foo, Bar] But you can only use this in a Rackup File. So second, you need to create a File called config.ru (Rackup File) with the following contents: require './app' run Rack:

port in use when not using a port

北城以北 提交于 2019-12-04 21:05:08
问题 I'm trying to run the following Sinatra application and am getting an error message telling me that I can't start a server, either because port's already in use or because I don't have root privileges. I have never had this problem before starting a Sinatra application. I updated to Mountain Lion for my mac a few days ago and wonder if this might be the cause of the problem. I also use RVM. Can anyone provide a suggestion... require "sinatra" class MyApp < Sinatra::Base get '/' do "Hello from

Why can't the Mail block see my variable?

一笑奈何 提交于 2019-12-04 20:39:33
问题 I'm new to Ruby and wondering why I am getting an error in this situation using the 'mail' gem in a simple Sinatra app: post "/email/send" do @recipient = params[:email] Mail.deliver do to @recipient # throws error as this is undefined from 'server@domain.com' subject 'testing sendmail' body 'testing sendmail' end erb :email_sent end This however works fine: post "/email/send" do Mail.deliver do to 'me@domain.com' from 'server@domain.com' subject 'testing sendmail' body 'testing sendmail' end

Unable to access Sinatra app on host machine with Vagrant forwarded ports

拟墨画扇 提交于 2019-12-04 20:17:20
问题 After starting my Sinatra application with both ruby app.rb and foreman start I am unable to access my application with localhost and the respective port on my host machine. I am also able to curl to the applications from within the shell of on guest machine, whereas on the host machine the curl request fails. As far as I know there shouldn't be a firewall in place on the guest machine because I'm using the Vagrant Ubuntu image. My Vagrantfile is as follows: Vagrant.configure('2') do |config|

Sinatra on Nginx configuration - what's wrong?

让人想犯罪 __ 提交于 2019-12-04 20:08:26
问题 I followed this tutorial more or less... I installed the passenger gem, executed passenger-install-ginx-module, sucessfully installed nginx and inserted this into the config: server { listen 80; server_name localhost; root /home/admin/sintest/public; # <--- be sure to point to 'public'! passenger_enabled on; } In /home/admin/sintest I have: an empty public folder, the config.ru: require 'sinatra' set :env, :production disable :run require './app.rb' #the app itself run Sinatra::Application