sinatra

Override Sinatra default NotFound error page

我怕爱的太早我们不能终老 提交于 2019-12-03 02:47:22
Is there a way to override the sinatra default NotFound error page ("Sinatra doesnt know this ditty")? I want sinatra to show only a plain string as "Method not found" when it does not found the proper route, but when I raise an 404 error from inside a route I want it to show the passed-in error message. Implementing the not_found block like this: not_found do 'Method not found.' end works, but its not a valid option since I want to be able to throw my own NotFound error messages from routes like this: get '/' do begin # some processing that can raise an exception if resource not found rescue

Sinatra and session variables which are not being set

柔情痞子 提交于 2019-12-03 02:44:29
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}/edit" end before do content_type "text/html", :charset => "utf-8" @user = session[:user] end get "

Devise with Sinatra

落花浮王杯 提交于 2019-12-03 02:43:32
Does anyone had installed Devise gem with Sinatra? Devise is based on Warden and so it should work on Sinatra, I couldn't find any related info about how to implement it. Bobby Calderwood Devise is really just a Rails-centric wrapper with nice helpers for warden , which is the underlying Rack authentication framework. So if you're using Sinatra in conjunction with Rails, you can use Devise in your Rails app, and use warden directly in your Sinatra app, and they will see the same user session data. So no, you can't use Devise directly within your Sinatra app, but if you're building a modular

Decoding Facebook's signed request in Ruby/Sinatra

对着背影说爱祢 提交于 2019-12-03 02:41:37
Due to Facebook deprecating new FBML, I'm looking for a new way to create a "reveal" tab (a page tab that shows one version to fans and another to non-fans). Facebook has added data to the signed_request: When a user selects your app in the left-hand menu, the app will receive the signed_request parameter with one additional parameter, page, a JSON array which contains the ‘id’ of the Facebook Page your Tab is hosted within, a boolean (‘liked’) indicating whether or not a user has liked the Page, and a boolean (‘admin’) indicating whether or not the user is an ‘admin’ of the Page along with

What are the main differences between Sinatra and Ramaze?

☆樱花仙子☆ 提交于 2019-12-03 02:06:47
问题 I'm looking for a lightweight Ruby web framework and have come across Sinatra and Ramaze. Both seem extemely light, concise and simple. But I don't know enough about either to say what the main distinctions are. Perhaps someone with experience with one or both of these could comment? 回答1: Sinatra does not enforce MVC. 回答2: Other lightweight Ruby frameworks I like _why's Camping (now maintained by the community) which has to be the lightest of them all (for recent info [>= v1.9] see the

What python equivalent of Sinatra would you recommend? [closed]

帅比萌擦擦* 提交于 2019-12-03 01:17:29
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. I like the sinatra framework, but might have to work in python. A quick web search has uncovered a few python equivalents including itty , flask and juno . I'd like to know people's experience of these, or other sinatra equivalents. Which would you recommend

Deleting the current session with Rack::Session::Cookie

与世无争的帅哥 提交于 2019-12-03 01:14:20
I feel like I'm missing something obvious here, and I'm hoping that as soon as I post this someone will shame me with the google search link I was missing :-) enable :sessions get '/logout' do # What goes here to kill the session? end Jonas Fagundes Just use session.clear to destroy the session. It depends how you create your session. Simply you have to nulify session entry. Here is simple example, how to create and destroy sessions. get '/login' do session[:username] = params[:username] "logged in as #{session[:username]}" end get '/logout' do old_user = session[:username] session[:username]

Sinatra, JavaScript Cross-Domain Requests JSON

折月煮酒 提交于 2019-12-03 00:51:48
I run a REST-API build on top of Sinatra. Now I want to write a jQuery Script that fetches data from the API. Sinatra is told to response with JSON before do content_type :json end A simple Route looks like get '/posts' do Post.find.to_json end My jQuery script is a simple ajax-call $.ajax({ type: 'get', url: 'http://api.com/posts', dataType: 'json', success: function(data) { // do something } }) Actually everything works fine as long as both runs on the same IP, API and requesting JS. I already tried to play around with JSONP for Rack without any positive results, though. Probably I just need

Sinatra, MySQL and ActiveRecord

人走茶凉 提交于 2019-12-03 00:49:17
how do I set up a simple sinatra app to use MySQL and ActiveRecord? I found some solutions, but none of them worked (maybe they are outdated): http://ericfarkas.com/posts/sinatra-activerecord-and-mysql/ http://labs.thredup.com/setting-up-sinatra-with-mysql-and-activerecor So what is the best practise method, to use Sinatra along with MySQL and ActiveRecord? The https://github.com/janko-m/sinatra-activerecord gem is only for sqlite3, as far as I can see. I'm not sure if I need models or just plain SQL queries. But getting it to work all together would help me a lot. This is a dead simple

Automatic logging of DataMapper queries

风流意气都作罢 提交于 2019-12-02 22:44:27
I am working on a simple app in Sinatra with DataMapper. I want to see the queries that DM is created for my various chained finders, etc. I have tried: DataMapper::Logger.new(STDOUT, :debug) in my configure do ... end block in an environment.rb file that loads when the app is started. I have also tried: DataMapper::Logger.new('log/my-app.log', :debug) Neither yields log statements from the app accessed either through a browser or through an irb session that requires my app. I do see the app starting message. I am using rackup config.ru to run the app locally. What am I missing? It seems that