How do you debug a Sinatra app like a Rails app?
You could try adding a before filter that prints out the parameters before do puts ‘[Params]’ p params end
You could try adding a before filter that prints out the parameters before do puts ‘[Params]’ p params end
Sinatra and Rails use the path public for static content – e.g., ./public/javascripts/. All files in these paths would then be served by the web server (e.g. Thin, Passenger), but without the need for /public in the URL (e.g. the file at #{my_app_root}/public/javascripts/application.js would be available via the Web at the URL http://#{my_domain}/javascripts/application.js).
Redirect in Sinatra is the most simple to use. So the code below can explain: require ‘rubygems’ require ‘sinatra’ get “https://stackoverflow.com/” do redirect “http://example.com” end You can also redirect to another path in your current application like this, though this sample will delete a method. delete ‘/delete_post’ do redirect ‘/list_posts’ end A very common place … Read more
With negative look-ahead: before /^(?!\/(join|payment))/ do # … end With pass: before do pass if %w[join payment].include? request.path_info.split(“https://stackoverflow.com/”)[1] # … end Or you could create a custom matcher.
If you’re using Sinatra, I can’t recommend DataMapper highly enough. I have a couple Rails apps where I’m stuck with ActiveRecord, and I’m constantly cursing its shortcomings and design flaws. If you’re on Sinatra, DataMapper is a very practical choice. require “rubygems” require “sinatra” require “datamapper” DataMapper.setup(:default, “sqlite3::memory:”) class Post include DataMapper::Resource property :id, Integer, … Read more
Summary Use require ‘pry’ at the top of your application. Call binding.pry in your code whenever you want to drop into the interactive session. For information on using Pry, see Turning IRB on its head with Pry and the Pry wiki. When you are done with a particular interactive session, type exit or Ctrl-D; Sinatra … Read more
Sinatra uses Rack::Protection, in particular the frame_options option, which is what is setting the X-Frame-Options header. You can configure which protections are used. Sinatra turns most of them on by default, (some are only enabled if you also are using sessions, and Rack::Protection itself doesn’t enable some by default). To prevent sending the X-Frame-Options header … Read more
There is a new framework called Nancy for .NET which is inspired by Sinatra and looks promising. But it is still in a very early state. You can read more about it here: http://elegantcode.com/2010/11/28/introducing-nancy-a-lightweight-web-framework-inspired-by-sinatra/ and
Inside your Sinatra app, you just have to require the bundler setup: require “bundler/setup” require “sinatra” get “https://stackoverflow.com/” do “Hello world!” end Alternatively, if you don’t want to add the additional require “bundler/setup” at the top of your app, you can instead invoke sinatra via bundle exec (e.g. bundle exec ruby myapp.rb) This assumes that … Read more
Did not try it, but should not be too hard: require ’em-websocket’ require ‘sinatra/base’ require ‘thin’ EM.run do class App < Sinatra::Base # Sinatra code here end EM::WebSocket.start(:host => ‘0.0.0.0’, :port => 3001) do # Websocket code here end # You could also use Rainbows! instead of Thin. # Any EM based Rack handler should … Read more