sinatra

Sinatra Request Object

别来无恙 提交于 2019-12-07 13:13:35
问题 I'm probably missing something painfully obvious here, but I can't seem to find an answer, or work it out myself. In Sinatra, they have a self.get method, which captures blocks, when a block is called, you're able to use the request variable inside, how is this possible? Sinatra module Sinatra class Base class Request < Rack::Request end attr_accessor :request def call!(env) @request = Request.new(env) end class << self def get(path, opts = {}, &block) ... end end end end App class App <

Devise authentication for sinatra app mounted in Rails

我怕爱的太早我们不能终老 提交于 2019-12-07 12:14:32
问题 I am using - Rails 3.2.2 Ruby 1.9.3 Devise 2.0.4 my route file looks like this: Foo::Application.routes.draw do devise_for :admins root :to => "home#index" authenticate :admin do mount Simple::App, at: '/simple' end end access under /simple needs to be authenticated. However if not signed in , access to /simple/* will be redirect to /simple/admin/sign_in instead of just /admin/sign_in which creates a redirect loop. Do I need to create a custom failure_app to correct this behavior? Thanks! 回答1

Exclude some paths from global authentication in Sinatra

别说谁变了你拦得住时间么 提交于 2019-12-07 10:44:27
I have an API in Sinatra, using a middleware doing a global restrict authentication with token. This middleware inserts the authentication check in a before statement, in order to protect everything globally without the need to add a check in each route definition. before do denied unless authorized? or env['PATH_INFO'] == '/auth/login' or env['REQUEST_METHOD'] == 'OPTIONS' # For AngularJS headers checks end But now I have some routes I need to exclude from this global restrictions (only 2 or 3 on tens) and don't know how to do that. I first think about Sinatra conditions : http://www

Heroku and Web scraping

 ̄綄美尐妖づ 提交于 2019-12-07 03:48:04
问题 I have a nokigiri web scraper that publishes to a database that I'm trying to publish to heroku. I have a sinatra application frontend that I want to have pull in from the database. I'm new to Heroku and web development, and don't know the best way to handle something like this. Do I have to place the web scraper script that uploads to the database under a sinatra route (like mywebsite.com/scraper ) and just make it so obscure that no one visits it? In the end, I'd like to have the sinatra

Build routes on top of a common base route?

我与影子孤独终老i 提交于 2019-12-07 03:07:41
问题 I have a common base path; say: get /base where I need to have basic auth performed and working for all sub calls under that path. Say: get /base/foo and get /base/bar . Looking at http://www.sinatrarb.com/intro.html#Helpers suggests I should be able to do this with the use of helpers. I was looking at the pass helper and use of call under triggering a new route in the documentation. But, another suggestion I read was using dynamic routing using regexes IE %r{/base/?:(path)?} or some such. So

Sinatra/Ruby default a parameter

一个人想着一个人 提交于 2019-12-07 02:28:41
问题 Is there a way to default a parameter in Sinatra? I am currently looking to see if 'start' was passed as a parameter, but it seems a little hacky. It would be nice if I could tell Sinatra to default certain parameters if they are not specified. get '/comments/?' do # want to setup page stuff, default to first page if not specified params[:start] = 0 if !params[:start] end Any ideas? 回答1: It's true that you can use ||= in this way, but it's a very strange thing to set the params after

error happens when I try “all” method in datamapper

。_饼干妹妹 提交于 2019-12-07 01:54:08
问题 When I try to do this in Sinatra, class Comment include DataMapper::Resource property :id, Serial property :body, Text property :created_at, DateTime end get '/show' do comment = Comment.all @comment.each do |comment| "#{comment.body}" end end It returns this error, ERROR: undefined method `bytesize' for #<Comment:0x13a2248> Could anyone point me to the right direction? Thanks, 回答1: Your getting this error because Sinatra takes the return value of a route and converts it into a string before

Passenger Rack app 'cannot infer basepath'

吃可爱长大的小学妹 提交于 2019-12-07 01:07:26
问题 This question was migrated from Server Fault because it can be answered on Stack Overflow. Migrated 9 years ago . I have a simple config.ru file for my Sinatra app. require 'sinatra' require 'app' run Sinatra::Application However, Passenger is failing with the error no such file to load -- app . I've tried using the 1.9 method require_relative but that now causes the error cannot infer basepath . I'm currently using the very hacky require File.join(File.dirname(__FILE__), 'app' ) , which is

What's the fastest way for a true sinatra(ruby/rack) after_filter?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 00:12:12
问题 Okay it's a simple task. After I render html to the client I want to execute a db call with information from the request. I am using sinatra because it's a lightweight microframework, but really i up for anything in ruby, if it's faster/easier(Rack?). I just want to get the url and redirect the client somewhere else based on the url. So how does one go about with rack/sinatra a real after_filter. And by after_filter I mean after response is sent to the client. Or is that just not dooable

Is this concept of Oauth2 workflow for sinatra + angular.js + custom provider correct?

我怕爱的太早我们不能终老 提交于 2019-12-06 23:42:29
I want to build three example apps. One will be a sinatra oauth2 provider and second will be rails app with angular.js on frontend and rails on backend and third with sinatra on backend and angular.js on frontend. Our Rails/Sinatra app will be authenticate users using satelizer and our custom provider. These is our Oauth2 workflow right now. Using Satellizer we get the authorization code from provider. We send this code to our backend. In backend using this authorization code, secret key and other params, we send an request to provider to get an access token. Using this obtain access token we