sinatra

Save Image in Elasticsearch with Ruby

梦想与她 提交于 2019-12-08 03:14:58
问题 I'm using Elasticsearch as a datastore for my Ruby/Sinatra app, and I'm wanting to save images. Is there a way to index an image as a binary into ES? If so, how should I go about doing this and then converting the binary back to an image in order to display it on the site? 回答1: Elasticsearch can store binary data using the binary type. The binary type needs to be base64 encoded and will not be indexed by default. Here is an example es mapping POST http://localhost:9200/adimages/ { "mappings"

Adaptive images for ruby based servers

蹲街弑〆低调 提交于 2019-12-08 01:30:23
问题 I'd like to deliver images to client based on the size of the user screen, as in If I have High resolution image, and the user want to view it on a mobile I don't want to send the full HD image, instead I'd like to send the image shrinked to the user's device dimension which will increase the loading speed on low bandwidth devices There is a solution for this here Adaptive Images detects your visitor's screen size and automatically creates, caches, and delivers device appropriate re-scaled

Why am I getting 404 errors with Sinatra with Passenger under nginx?

痞子三分冷 提交于 2019-12-08 01:04:18
问题 I have a Sinatra-based app that runs fine locally. I moved it to a nginx-based server with Passenger and now all my links to files in my apps /public are returning 404 errors. The primary app runs, is able to access the HAML templates in /view , which render correctly. The files exist and permissions are correct; I can open and edit them so I know they're there. In my HAML templates I'm referring to the files that I can't access like this: %script{ :src => 'js/jquery.js' } %link{ "rel" =>

Why would I get “Errno::ENOENT: No such file or directory” when viewing a Sinatra form?

◇◆丶佛笑我妖孽 提交于 2019-12-07 22:58:11
问题 I am trying to follow this tutorial: http://net.tutsplus.com/tutorials/ruby/singing-with-sinatra/ Got stuck in "We’ll also make use of a “ view file ”, which allows us to split the markup for a view into a separate file. " I have my basics.rb file running fine. And My files are stored as follows: Desktop/RubyForm/basics.rb Desktop/RubyForm/view/form.erb However, now when i go to http://localhost:9393/form , I am greeted with: Errno::EIO at /form Input/output error - <STDERR> file: lint.rb

Test with Rspec using session sinatra

北慕城南 提交于 2019-12-07 17:05:51
问题 I have sinatra appliction using session, how do I test a page that uses session? I using Rspec + sinatra Tks 回答1: This page, show's the main problem of testing session with rspec and sinatra . The main problem is that the variable session is not accessible from the test code. To solve it, it suggests (and I confirm) to add the fowling lines at spec/spec_helper.rb : def session last_request.env['rack.session'] end It will make accessible a mocked session object from the last request at the

How do I get Twitter Bootstrap's Less files to work with Sinatra AssetPack?

淺唱寂寞╮ 提交于 2019-12-07 15:46:42
问题 I am trying to get Bootstrap's Less files working with Sinatra AssetPack, but I am getting Less parser errors. These errors lead me believe that the less files being imported through bootstrap.less are not aware of each other. I have an app.rb file: require 'sinatra/base' require 'sinatra/assetpack' class App < Sinatra::Base set :root, File.dirname(__FILE__) register Sinatra::AssetPack assets do css :bootstrap, [ '/css/bootstrap.css' ] end get '/' do erb :index end # start the server if ruby

Run background process in Sinatra

大城市里の小女人 提交于 2019-12-07 15:27:21
问题 I have got Sinatra/Rails app and an action which starts some long process. Ordinary I make a queue for background jobs. But this case is too simple and background process starts very rarely, so queue is an overhead. So how could I run background process without queue? get "/build_logs/:project" do LogBuilder.new(params[:project]).generate "done" end I've tried to make it as a new Thread or Process fork, but it didn't help. 回答1: I have had success with this (simplified) in Sinatra: get '/start

Universal settings in Sinatra

僤鯓⒐⒋嵵緔 提交于 2019-12-07 15:05:18
问题 I have a class in Sinatra where I set some settings (from JSON, as it happens): class Pavo < Sinatra::Base configure :development do set :config, JSON.parse(File.open(File.dirname(__FILE__) + "/pavo.configuration.development.json", "rb").read) set :config_mtime, File.mtime(File.dirname(__FILE__) + "/pavo.configuration.development.json") end [...] get '/' do puts "whatever" end end And that class has a model, that is required to read those settings. class Resolver < Sinatra::Base def get_data

Heroku and Datamapper problems

我怕爱的太早我们不能终老 提交于 2019-12-07 14:11:40
问题 I can launch a basic app on Heroku, displaying a message with get '/'... works just fine. However, whenever I try to add sqlite with datamapper, the thing breaks down. In order to see my app structure, check out the project on github. I've kept the code pretty bare-bones. In the log from heroku I'm getting: 2011-06-26T21:28:36+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/adapters.rb:163:in `require': no such file to load -- dm-postgres-adapter (LoadError) The

Rails + Sinatra apps sharing sessions

怎甘沉沦 提交于 2019-12-07 13:38:26
问题 I haven't found a good answer to this yet. How can I get my Rails app and Sinatra app (mounted in my Rails app's config.ru) to share a session successfully? If I visit my Sinatra app first, then the Rails app, I get an error like undefined method sweep for {}:Hash , presumably because Rails uses a custom subclass of Hash for storing session info, and Rack::Session::Cookie doesn't. My code so far: config.ru map "/" do run MyRailsApp::Application end map "/sinatra" do use Rack::Session::Cookie,