sinatra

Route Handlers Inside a Class

给你一囗甜甜゛ 提交于 2019-12-29 04:19:12
问题 I have a Sinatra app setup where most of the logic is performed inside of various classes, and the post / get routes instantiate those classes and call their methods. I'm thinking about whether putting the post / get route handlers inside of the classes themselves would be a better structure. In any case, I'd like to know if it is possible. So for instance: class Example def say_hello "Hello" end get '/hello' do @message = say_hello end end Without modification to the above, Sinatra will say

Get absolute (base) url in sinatra

血红的双手。 提交于 2019-12-29 03:39:08
问题 Right now, I do a get '/' do set :base_url, "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}" # ... haml :index end to be able to use options.base_url in the HAML index.haml. But I am sure there is a far better, DRY, way of doing this. Yet I cannot see, nor find it. (I am new to Sinatra :)) Somehow, outside of get , I don't have request.env available, or so it seems. So putting it in an include did not work. How do you get your base url? 回答1: A couple things. set is a class

How do I automatically generate static HTML from HAML with Sinatra or Padrino?

梦想的初衷 提交于 2019-12-25 08:15:55
问题 I want to serve static HTML pages using nginx . Then, I will use jQuery to update DIVs, SPANs, etc via AJAX calls from a Padrino server. I like creating my web pages in HAML because it's easier but in production, I don't want to serve HAML templates. Just raw, HTML at the speed of nginx. Is there an easy way to do this? What would be ideal would be a service that automatically renders HAML, partials, etc into the public folder that nginx could serve. 回答1: Simple, add padrino-cache to your app

Error running Extreme Startup Sinatra web server

我与影子孤独终老i 提交于 2019-12-25 07:04:51
问题 I'm trying to set up and run the Extreme Startup coding dojo on my Windows machine. When I try to access the front page on http://localhost:3000, I get this error: application error Errno::ENOENT at / No such file or directory @ rb_sysopen - c:/Users/mark/Desktop/extreme_startup/lib/extreme_startup/views/leaderboard.haml file: template.rb location: initialize line: 210 BACKTRACE (expand) JUMP TO: GET POST COOKIES ENV c:/Users/mark/Desktop/extreme_startup/lib/extreme_startup/web_server.rb in

Testing Datamapper models with RSpec

China☆狼群 提交于 2019-12-25 05:29:13
问题 I'm testing a Sinatra application, which is using DataMapper, with RSpec. The following code: it "should update the item's title" do lambda do post "/hello/edit", :params => { :title => 'goodbye', :body => 'goodbye world' } end.should change(Snippet, :title).from('hello').to('goodbye') end Results in this error: title should have initially been "hello", but was #<DataMapper::Property::String @model=Snippet @name=:title> I can of course hack this by removing the lambda and only checking if:

Thin + EventMachine fails to start

谁说我不能喝 提交于 2019-12-25 05:23:09
问题 While loading a Thin webserver for a sinatra app I keep getting Unable to load the EventMachine C extension; To use the pure-ruby reactor, require em/pure_ruby'<path>/vendor/bundle/ruby/1.9.1/gems/eventmachine-1.0.0.rc.4/lib/eventmachine.rb:8:in `require': cannot load such file -- rubyeventmachine (LoadError) from <path>/vendor/bundle/ruby/1.9.1/gems/eventmachine-1.0.0.rc.4/lib/eventmachine.rb:8:in `<top (required)>' from <path>/vendor/bundle/ruby/1.9.1/gems/thin-1.5.0/lib/thin.rb:7:in

Acceptance testing of sinatra app using webrat fails

痴心易碎 提交于 2019-12-25 05:16:27
问题 I am trying to test a ruby authentication app using minitest and webrat but get errors. Tests like visit '/' fail with an error Status 200 expected but was 404. Tests containing code like fill_in :email, :with => "first@company.com" fail with error Could not find field: :email . I read several sinatra, testing and webrat documents and forums. Some of them were old and suggested stuff like Sinatra::Default, but github.com/brynary/webrat/wiki/sinatra, Building a Sinatra App Driven By Webrat

Getting Sinatra running on Ubuntu, Uninitialized constant error

六眼飞鱼酱① 提交于 2019-12-25 02:53:34
问题 Trying to get Sinatra setup on Ubuntu 12.04. I have RVM installed, and I think I have installed all dependencies (listed below). I found another SO post (here) that indicated I don't have libssl-dev installed, but it looks like I do. When I run: sudo gem install sinatra I get: ERROR: While executing gem ... (NameError) uninitialized constant Gem::RemoteFetcher::OpenSSL rvm req installs: sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev

SWIG: Ruby overloading problems

风流意气都作罢 提交于 2019-12-25 02:48:07
问题 I have a sinatra web application and a C++ library that I can 'require' in sinatra (ruby) using bindings created by swig. I also have a second -very similar- library, in which the function names are partially the same as in the first one. When I require them both, the one that is loaded first 'wins', i.e. calls to the ambiguous function names are always mapped to this library. The reason is that 'require' does only load stuff that is not already loaded, whereas 'load' reloads no matter what.

Sinatra Gem Won't Install

我们两清 提交于 2019-12-25 02:19:40
问题 I am running Ubuntu 10.04 on a linode trying to get sinatra, passenger, nginx, and rvm to all play nice with Ruby 1.9.2. I'm running into an issue with gems though: ~/.rvm/gems/ruby-1.9.2-p290/gems$ ls returns daemon_controller-0.2.6 fastthread-1.0.7 passenger-3.0.9 rack-1.3.2 rake-0.9.2 and gem list returns *** LOCAL GEMS *** rack (1.3.2) rake (0.9.2) sinatra (1.2.6) tilt (1.3.3) What is odd to me is that they aren't the same. And sinatra is missing from the .rvm gems. When I go to my