sinatra

Access Sinatra settings from a model

霸气de小男生 提交于 2019-12-10 17:56:47
问题 I have a modular Sinatra app. I'm setting some custom variables in my configure block and want to access these settings in my model. The problem is, I get a NoMethodError when I try and access my custom settings from MyModel . Standard settings still seem to work fine though. How can I make this work? # app.rb require_relative 'models/document' class App < Sinatra::Base configure do set :resource_path, '/xfiles/i_want_to_believe' end get '/' do @model = MyModel.new haml :index end end #

SQLite3::IOException: disk I/O error on SELECT

丶灬走出姿态 提交于 2019-12-10 17:11:42
问题 I have a Sinatra application using the Sequel gem against a sqlite3 database. I've been developing on a MacBook Pro running Mavericks. I have been running the app locally using the shotgun gem and everything has been working just fine. Recently I decided to run the application with Passenger and Nginx. When I run the application under passenger/nginx, the app errors out with the following in the logs App 17805 stdout: E, [2014-02-09T20:44:42.491448 #17805] ERROR -- : SQLite3::IOException:

Database connection pooling

。_饼干妹妹 提交于 2019-12-10 16:38:59
问题 I created a small chat application in Sinatra and jQuery on heroku. It simply inserts a message to a database when user submits it. And also downloads new messages every 2 seconds. After a few minutes of testing it stopped working and I received an email form heroku: Hi, We noticed that the gisekchat app had a large number of connections open to the shared database. We had to limit the number of connections to the shared database due to performance reasons. Can you either reduce the number of

Sinatra: How to respond with an image with headers “content-type” => “image/jpeg”

不问归期 提交于 2019-12-10 15:45:55
问题 Example: require 'sinatra' get '/somekey' do headers('Content-Type' => "image/jpeg") ["http://upload.wikimedia.org/wikipedia/commons/2/23/Lake_mapourika_NZ.jpeg", "http://img.brothersoft.com/screenshots/softimage/j/jpeg_converter-4567-1.jpeg"].sample end I want to respond with an image that is not hosted on my server. How would I get about this? Note: The link to the image is not secret (as it is hosted on S3). It is for a site that generates identicons. Checkout http://identico.in/[insert

CTRL+C won't stop a sinatra app

可紊 提交于 2019-12-10 15:29:57
问题 Normally when I run a rails app from the console during development I can just press Ctrl + C and it exits. Then I can run the app again, thus bouncing it and effecting changes. I am running a sinatra app. I just run the ruby file. $: ruby myapp.rb When I press Ctrl + C , however, it won't stop the app. I've had to bring up the Ubuntu System Monitor and kill the Ruby process. Very annoying. Anyone seen this/dealt with this before? 回答1: I installed the 'thin' gem and it works fine. Apparently

What are the best ways to run a Ruby script as a subprocess/another thread from Sinatra?

萝らか妹 提交于 2019-12-10 15:29:42
问题 I have a Sinatra app I plan on hosting on Heroku. This application, in part, scrapes a lot of information from other pages around the net and stores the information to a database. These scrapping operations are a slow process, so I need them to run in another thread/process separate from my Sinatra app. My plan is just to have a button for each process that I can click and the scrapping will take place in the background. I'm unsure what's the best way to do this, complicated by what Heroku

jquery and random.org “is not allowed by Access-Control-Allow-Origin”

最后都变了- 提交于 2019-12-10 14:16:54
问题 I am having a problem requesting a random number from random.org using jQuery. When I'm using a static page and the following javascript, I don't have any issues getting random numbers. However, I am hosting a Sinatra app on Heroku (also, when running my app locally in production using Thin) I get "(website) is not allowed by Access-Control-Allow-Origin." function raffler(){ var rowCount = $('#winnerTable tr').length; $('#winnerButton').click(function() { $.get("http://www.random.org/integers

Sidekiq server not loading configuration file

流过昼夜 提交于 2019-12-10 13:55:30
问题 I'm trying to setup sidekiq with my sinatra application, and I'm having trouble starting up the sidekiq workers to run in the daemon mode, with a configuration file. My project has the following structure: project - config -- sidekiq.yml #Sidekiq Config File - app -- app.rb #Sinatra Application File - Rakefile - Gemfile - etc. The ultimate goal is to create some rake tasks to handle all sidekiq tasks. For now, I'm just trying to the get things to work correctly via the command line, and then

Ruby Sinatra - Protecting routes with authentication

和自甴很熟 提交于 2019-12-10 11:45:33
问题 I have a Ruby class that basically authenticates a user to an LDAP directory as follows. The DirectoryUser class is using the net/ldap gem to do this. When called the class returns either a 'true' if the user is authenticated or 'false' if not. >>DirectoryUser.authenticate('user', 'password') #True I want to use this mechanism to protect my routes in a basic Sinatra application for multiple users. Is there a recommended way to do this that follows best practise? Could somebody show how this

Sinatra doesn't show exceptions in log file

断了今生、忘了曾经 提交于 2019-12-10 11:26:07
问题 I'm coming from Rails to sinatra, and I have some problems using logging. I have a Sinatra app, that does it's logging like so: configure do Logger.class_eval { alias :write :'<<' } logger = Logger.new("log/#{settings.environment}.log") use Rack::CommonLogger, logger end All requests are logged properly, I see sth like 127.0.0.1 - - [25/May/2013 10:34:21] "GET / HTTP/1.1" 200 30 0.0021 127.0.0.1 - - [25/May/2013 10:34:22] "GET /favicon.ico HTTP/1.1" 404 18 0.0041 Inside the log files. But I