sinatra

How to test Sinatra app using session

空扰寡人 提交于 2019-12-18 17:13:43
问题 How to test Sinatra application wich is using session? get "/", {}, {'rack.session' => { 'foo' => 'blah' } } This code doesn't work for me, I have 'enable :sessions' in my app. 回答1: It looks like the problem is actually to have enable :sessions activated. You have to deactivate this setting in order to be available to overwrite the session . The solution could be: # my_test.rb (first line, or at least before you require your 'my_app.rb') ENV['RACK_ENV'] = 'test' # my_app.rb (your sinatra

How to test Sinatra app using session

我是研究僧i 提交于 2019-12-18 17:13:28
问题 How to test Sinatra application wich is using session? get "/", {}, {'rack.session' => { 'foo' => 'blah' } } This code doesn't work for me, I have 'enable :sessions' in my app. 回答1: It looks like the problem is actually to have enable :sessions activated. You have to deactivate this setting in order to be available to overwrite the session . The solution could be: # my_test.rb (first line, or at least before you require your 'my_app.rb') ENV['RACK_ENV'] = 'test' # my_app.rb (your sinatra

Sinatra Warden with existing Ruby on Rails application that uses Devise

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 17:08:17
问题 I am trying to split my current Ruby on Rails 3 web-application and it's web-services (API). My web-application is running on Heroku and implements API as a namespaced route within my application. For example /events returns a HTML page and /api/v1/events returns a JSON data. According to some best practices, I want to split those into two different applications. I have chosen Sinatra to implement the API application. It works now for simple requests where authentication is not required. My

How to convert a Net::HTTP response to a certain encoding in Ruby 1.9.1?

≯℡__Kan透↙ 提交于 2019-12-18 15:35:33
问题 I have a Sinatra application (http://analyzethis.espace-technologies.com) that does the following Retrieve an HTML page (via net/http) Create a Nokogiri document from the response.body Extract some info and send it back in the response. The response should be UTF-8 encoded So I came to the problem while trying to read sites that use windows-1256 encodings like www.filfan.com or www.masrawy.com. The problem is the result of the encoding conversion is not correct though no errors are thrown.

Passwords in git tree + Heroku + Github

一世执手 提交于 2019-12-18 12:55:21
问题 I have a very basic application done in Sinatra I have deployed it in Heroku (http://frasesbarrio.heroku.com) There is a button for sharing in Facebook and in fact it can be used as a Facebook application. For Facebook authentification, my application has its own app id and app secret (right now they are two constants in the main file of the source) I also want to share my code in Github for everyone to enjoy. How can I send the code with the app id and secret to Heroku and without them to

How do I make Rake tasks run under my Sinantra app/environment?

喜你入骨 提交于 2019-12-18 12:27:34
问题 I'm using Sinatra, and I wanted to set up some of the convenience rake tasks that Rails has, specifically rake db:seed . My first pass was this: namespace :db do desc 'Load the seed data from db/seeds.rb' task :seed do seed_file = File.join(File.dirname(__FILE__), 'db', 'seeds.rb') system("racksh < #{seed_file}") end end racksh is a gem that mimics Rails' console. So I was just feeding the code in the seed file directly into it. It works, but it's obviously not ideal. What I'd like to do is

Installing a gem from Github with Bundler

点点圈 提交于 2019-12-18 11:46:43
问题 I am trying to use the instructions here to install a pre-released version of a gem with bundler. The "bundle install" output lists the gem as getting installed, but "gem list" fails to find it. My Gemfile: source :gemcutter gem 'sinatra', '1.1.0', :git => 'http://github.com/sinatra/sinatra.git' gem 'RedCloth', '4.2.3' Here is a gist with the rest of my sample code. Has anyone gotten this scenario to work? NOTE: I am also using RVM (on OS X). bundle show does list the gem (and dependencies)

Sinatra static assets are not found when using rackup

一个人想着一个人 提交于 2019-12-18 11:12:09
问题 I have a simple Sinatra app that is configured using the modular style. When I start the app using rackup -p 4567 as recommended in the readme file, the static assets in the public folder are not served. But when I start it using shotgun ./config.ru -p 4567 then they are served. Why does this happen? Could this happen in production? Here is my code: # config.ru require 'rubygems' require 'bundler' require 'sinatra' require 'jammit' Bundler.require Jammit.package! require File.expand_path('.

Cannot access local Sinatra server from another computer on same network

家住魔仙堡 提交于 2019-12-18 10:07:14
问题 I have a simple Sinatra server that I run through textmate but I can't access from another computer on the same network. I'm running Ruby 1.9.3p327 and Sinatra 1.4.1 on a Mac OS 10.8.3. Firewall is disabled. I tested the same scenario on different networks and computers. The computer responds to simple pings but when I try to telnet port 4567 I can't establish a connection. 回答1: There was a recent commit to Sinatra that changed the default listen address to localhost from 0.0.0.0 in

How do I set up a Sinatra app under Apache with Passenger?

情到浓时终转凉″ 提交于 2019-12-18 09:59:34
问题 Let's say I have the simplest single-file Sinatra app. The hello world on their homepage will do. I want to run it under Apache with Phusion Passenger, AKA mod_rails. What directory structure do I need? What do I have to put in the vhost conf file? I understand I need a rackup file. What goes in it and why? 回答1: Basic directory structure: app |-- config.ru # <- rackup file |-- hello-app.rb # <- your application |-- public/ # <- static public files (passenger needs this) `-- tmp/ `-- restart