sinatra

Simple way to test an HTTPS (SSL) request with RSpec

回眸只為那壹抹淺笑 提交于 2020-01-13 19:39:09
问题 I want Rspec to request the root using https. This is what I currently have: it "requesting root (/) with HTTPS should return 200" do get "https://test.host/" last_response.should be_ok end Attempting the solution proposed in Test an HTTPS (SSL) request in RSpec Rails returns the following error: wrong number of arguments (0 for 1) I would assume I could do something like: get "/", :https => "on" Is there a way to request the root without specifying the host? 回答1: When using Sinatra and RSpec

Sinatra and session variables which are not being set

徘徊边缘 提交于 2020-01-12 03:32:09
问题 For some reason, session variables are not being set in my app. I am using Sinatra 1.2.1. Here is a piece of code: module GitWiki class App < Sinatra::Base configure do enable :sessions set :app_file, __FILE__ set :root, File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) set :auth do |bool| condition do redirect '/login' unless logged_in? end end end helpers do def logged_in? not @user.nil? end end error PageNotFound do page = request.env["sinatra.error"].name redirect "/#{page}

How to add “Access-Control-Allow-Origin” headers to API Response in Ruby

随声附和 提交于 2020-01-11 13:27:23
问题 I'm interviewing for a front-end developer job and have been given a coding test to build a simple front-end interface. I've been given the server, which has been written in Ruby (2.1.3) and has 3 endpoints which I am to make use of in my front-end client. I have no experience whatsoever with Ruby but I followed their instructions for setting up the server and it seems to work - I get responses from all the endpoints. The problem is that I'm not getting any response from my client app, which

How do I html_escape text data in a sinatra app?

限于喜欢 提交于 2020-01-11 08:26:11
问题 I have a small Sinatra app which generates html fragments for me from an ERB template. How do I html_escape the output? The <%=h somestring %> helper does not exist in Sinatra. 回答1: Rack::Utils includes a HTML escape method. http://www.sinatrarb.com/faq.html#escape_html 回答2: require 'CGI' get '/html' do erb :view end def h(html) CGI.escapeHTML html end __END__ @@view <% File.open('my.html') do |f| %> <%=h f.read() %> <% end %> 来源: https://stackoverflow.com/questions/2123586/how-do-i-html

Sinatra helper to fake a request

陌路散爱 提交于 2020-01-11 05:13:07
问题 Summary Within a Sinatra web app, how can I make a virtual request to the application and get the response body back as text? For example, these routes... get('/foo'){ "foo" } get('/bar'){ "#{spoof_request '/foo'} - bar" } ...should result in the response "foo - bar" when requesting "/bar" with the web browser. Motivation My application has a page representing an bug entry, with lots of details about that bug entry: what version was the bug experienced in, how important is it, what tags are

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed MAC

孤街醉人 提交于 2020-01-11 04:02:12
问题 I'm attempting to use the SoundCloud SDK for user authentication. My first route after a user clicks "sign in": get "/login" do client = Soundcloud.new(:client_id => 'MY_ID', :client_secret => 'MY_SECRET', :redirect_uri => 'http://localhost:9393/signed_in') redirect client.authorize_url() end I then have the next route where they are redirected: get "/signed_in" do client = Soundcloud.new(:client_id => '16d6ada1a0cfc5009f7d59d203a13b2f', :client_secret => '845df7d44dc4e359fedc8ed5944d29a5',

What ORM to use in one process multiple db connections sinatra application?

蹲街弑〆低调 提交于 2020-01-11 03:06:07
问题 Checked ActiveRecord, DataMapper, Sequel: some use globals (static variables) some require open db connection before loading source file with models. What ORM is better to use in sinatra application that uses different databases. 回答1: DataMapper is designed for multi-database use. You can set up multiple repositories just by saying something like DataMapper.setup(:repository_one, "mysql://localhost/my_db_name") . DataMapper then tracks all the repositories that have been setup in a hash that

Could someone give me an example of node.js application

不羁的心 提交于 2020-01-10 19:31:46
问题 I'm trying to understand the differences between some of the newer web programming frameworks that now exists, namely Node.js, Rails, and Sinatra. Could someone give me an example of applications that would work best on each of the frameworks? That is to say, what is an application that would be best suited for Node.js as opposed to Rails or Sinatra and what is an application that is best suited for Rails as opposed to Node.js and Sinatra etc..... 回答1: Sinatra and Rails are both web

stream multiple body using async sinatra

旧时模样 提交于 2020-01-10 09:21:26
问题 I would like start a long poll request from javascript which is fine and i expect my ruby prog to stream multiple body sections to the javascript. Why doesn the following (pseudo)code work? require 'rubygems' require 'sinatra/async' require 'eventmachine' require 'thin' require 'json' class Test < Sinatra:Base register Sinatra::Async aget '/process' do for c in 1..10 body { { :data => [ "this is part #{c}" ] }.to_json end end end run! end Maybe i misunderstood what long polling and async is

Padrino app with REST API

戏子无情 提交于 2020-01-06 13:02:47
问题 Within a Padrino application I have a posts controller with the conventional routes: Blog::App.controllers :posts do get :index do ... end get :show, :with => :id do ... end end This gives me therefore the normal URL access within the posts namespace http://blog.dev/posts http://blog.dev/posts/show/1 Now I want to provide access through a REST API from a different route outside the namespace , like for example: http://blog.dev/api/v1/post/all http://blog.dev/api/v1/post/1 How can I define the