Cuba.plugin Cuba::Render Cuba.define do on get do on "hello" do res.write render("hello.haml", content: "Hello, Cuba") end on root do res.redirect "/hello" end end end пятница, 28 декабря 12 г.
'sinatra/linkblocker' block_links_from 'digg.com' get "/events/recent.json" do Event.recent.to_json end # modular style require 'sinatra/base' require 'sinatra/diggblocker' module Posts class Application < Sinatra::Base register Sinatra::LinkBlocker block_links_from 'digg.com' get "/" do erb :index end end end пятница, 28 декабря 12 г.
enable :sessions get('/login') { haml :login } post('/login') do if params[:name] == 'admin' && params[:password] == 'admin' session['user_name'] = params[:name] else redirect '/login' end end end class MyApp < Sinatra::Base # middleware will run before filters use LoginScreen before do unless session['user_name'] halt "Access denied, please <a href='/login'>login</a>." end end get('/') { "Hello #{session['user_name']}." } end # config/routes.rb mount API::Endpoints, :at => "/api" пятница, 28 декабря 12 г.
use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions use ActionDispatch::RemoteIp use ActionDispatch::Reloader use ActionDispatch::Callbacks use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache use ActionDispatch::ParamsParser use ActionDispatch::Head use Rack::ConditionalGet use Rack::ETag run ApiApp::Application.routes use ActionDispatch::Static use Rack::Lock use Rack::Runtime use Rack::MethodOverride use ActionDispatch::RequestId use Rails::Rack::Logger use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions use ActionDispatch::RemoteIp use ActionDispatch::Reloader use ActionDispatch::Callbacks use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache use ActionDispatch::Cookies use ActionDispatch::Session::CookieStore use ActionDispatch::Flash use ActionDispatch::ParamsParser use ActionDispatch::Head use Rack::ConditionalGet use Rack::ETag use ActionDispatch::BestStandardsSupport run Application::Application.routes $ gem install rails-api пятница, 28 декабря 12 г.