sinatra

Simple and Ideal Logging in Sinatra

那年仲夏 提交于 2019-12-03 16:18:46
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 do def logger LOGGER end end i have written this in app.rb of my app, it fails saying undefined method

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

不打扰是莪最后的温柔 提交于 2019-12-03 16:15:28
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 gem and http://macournoyer.com/blog/2009/06/04/pusher-and-async-with-thin/ , thinking these would solve

How to ship a Sinatra application as a gem and deploy it?

耗尽温柔 提交于 2019-12-03 15:52:38
I have a sinatra application and packaged that as a gem . Its file-layout looks roughly like this: ├── bin │ └── tubemp ├── lib │ └── tubemp.rb ├── Gemfile └── tubemp.gemspec I can install and run it just fine. Calling ruby lib/tubemp.rb fires the app too, because Sinatra made it self-starting. tubemp.rb : class Tubemp < Sinatra::Application get '/' do erb :index, :locals => { :title => "YouTube embeds without third party trackers." } end end The binary is really simple too. bin/tubemp : #!/usr/bin/env ruby require "tubemp.rb" Tubemp.run! But now I want to deploy this as Rack-app. Or deploy it

gzip assets in Sinatra app

做~自己de王妃 提交于 2019-12-03 15:24:47
I have been reading that zipping your assets using gzip will increase the performance of a site. There seems to be many ways to do this in a Sinatra application, so i was looking to confirm the most effective and easiest way to understand. I have come across use Rack::Deflater Which should be placed in my config.ru file before running the app, so in my case require './david' use Rack::Deflater run Sinatra::Application is that it? is it this simple, Just to add I know this will zip all my static assets, including my images, but these are served from a CDN so would that make a difference? Ant

Running Ruby Sinatra inside a Docker container not able to connect (via Mac host) or find commands (in different scenario)?

五迷三道 提交于 2019-12-03 14:02:09
I've tried two forms of Dockerfile to get a simple Ruby/Sinatra app running, and in both scenarios it fails for different reasons (I'll explain both in a moment). Effectively I want to access the Sinatra web server from my host (Mac OS X using Boot2Docker). The app structure is: . ├── Dockerfile ├── Gemfile ├── app.rb ├── config.ru The contents of the files are: Dockerfile Version 1... FROM ruby RUN mkdir -p /app WORKDIR /app COPY Gemfile /app/ RUN bundle install --quiet COPY . /app EXPOSE 5000 ENTRYPOINT ["bash"] CMD ["bundle", "exec", "rackup", "-p", "5000"] Version 2... FROM ubuntu:latest

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

风流意气都作罢 提交于 2019-12-03 13:27:40
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 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::Cascade.new [Foo, Bar] and a file called app.rb with your actual app: require 'sinatra/base' class Foo <

Decoding Facebook's signed request in Ruby/Sinatra

送分小仙女□ 提交于 2019-12-03 13:17:12
问题 Due to Facebook deprecating new FBML, I'm looking for a new way to create a "reveal" tab (a page tab that shows one version to fans and another to non-fans). Facebook has added data to the signed_request: When a user selects your app in the left-hand menu, the app will receive the signed_request parameter with one additional parameter, page, a JSON array which contains the ‘id’ of the Facebook Page your Tab is hosted within, a boolean (‘liked’) indicating whether or not a user has liked the

Sinatra on Nginx configuration - what's wrong?

痴心易碎 提交于 2019-12-03 12:44:36
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 and a test sinatra app.rb: require 'sinatra' get '/' do "hello world!" end Now when I run nginx and open

Why can't the Mail block see my variable?

浪子不回头ぞ 提交于 2019-12-03 12:44:20
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 erb :email_sent end I suspect this is something to do with block scope and my misunderstanding of it.

How to mount a Sinatra application inside another Sinatra app?

主宰稳场 提交于 2019-12-03 12:23:00
I am trying to write a Sinatra application that groups components together (sort of like controllers). So for the "blog" related things, I want an app called Blog mounted at /blog . All of the routes contained in the Blog app would be relative to its mounted path, so I could simply define an index route without having to specify the mount path in the route. I originally handled this by using a config.ru file and map ing the routes to the different apps. The problem with this that I ran into, was that I was using various sinatra gems/extensions/helpers that needed to be included in all of the