sinatra

Can’t run ”gem install bundle’ in git bash terminal

僤鯓⒐⒋嵵緔 提交于 2019-12-21 02:59:10
问题 I'm new to Web development with Sinatra. I've been trying to run bundle install command in git-bash terminal, but it's says that: I've then tried to install bundler but then I'm kept getting this error: I can't even run gem install bundler command in git-bash terminal. Please tell me what to do ?? I'm working on windows 7 x64bit system. 回答1: Make sure that: ruby for Windows is installed your %PATH% is modified to reference ruby ( Advanced System Settings / Environment Variables / System

How to use sinatra session

最后都变了- 提交于 2019-12-20 20:18:22
问题 enable :sessions get '/foo' do session['m'] = 'Hello World!' redirect '/bar' end get '/bar' do session['m'] # => 'Hello World!' end It does not seem to work. 回答1: Are you using shotgun? If so, do the following: configure(:development) { set :session_secret, "something" } This will no longer be necessary in Sinatra 1.3. 回答2: Perhaps you have cookies disabled on your web browser? Sinatra's sessions use cookies by default. Here's my test app: require 'sinatra' enable :sessions get '/foo' do

Sinatra, Rack::Test, and Conditional GET requests

巧了我就是萌 提交于 2019-12-20 17:28:37
问题 I've got a Sinatra 1.2.0 app that is doing Last-Modified validation caching with Rack::Cache. Things are working great-- I call last_modified in my route body and if the cache has an up-to-date copy, the rest of the execution halts, my app responds to the cache with 304 Not Modified, and the cache serves the cached page without having to generate a new one. My issue is in trying to write tests for this process. Using Rack::Test and Minitest::Spec, I'm simulating the cache's conditional Get

Ruby w/ Sinatra: what is the equivalent of a .js.erb from rails?

六眼飞鱼酱① 提交于 2019-12-20 17:24:49
问题 .js.erb's are nice, because you can use them to replace parts of a page without having to leave the current page, which gives a cleaner and unchopped up feel to the site / app. Is there a way to use them in sinatra? or an equivalent? 回答1: Based on your description, I'm guessing that your desire is to have portions of a page editable and replaced via AJAX. If this is wrong, please clarify. I do this in my Sinatra apps by including (my own) AJAXFetch jQuery library and writing code as shown

Cannot access sinatra app through the local network

£可爱£侵袭症+ 提交于 2019-12-20 14:10:56
问题 I have rails application. If I start it with rails s (port 3000), it works perfectly both on my machine and every device on my local network via the ip address (192.168.0.3 in my case). I have sinatra application. If I start it with ruby app.rb (port 4567), it works perfectly on my machine, but it it is not accessible from other devices on my local network. Both application use Thin as an app server. Is it something related to how sinatra works? 回答1: Try ruby app.rb -o 0.0.0.0 or ruby app.rb

Override Sinatra default NotFound error page

可紊 提交于 2019-12-20 12:33:11
问题 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

Automatic logging of DataMapper queries

自闭症网瘾萝莉.ら 提交于 2019-12-20 10:32:16
问题 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

Expressing conditional HAML possibly with ternary operator

余生颓废 提交于 2019-12-19 18:21:30
问题 Trying to come up with a more compact way of expressing this conditional in HAML and Ruby, perhaps with a ternary operator: - if @page.nil? %br (nothing yet) - else %br #{@page.name} (looking for similar approach as per Neat way to conditionally test whether to add a class in HAML template) Your help would be appreciated :) 回答1: The code you have makes the text a child of the <br> element; that is not desirable. What you really meant, I think, was: %br - if @page.nil? (nothing yet) - else #{

Execute code once Sinatra server is running

时光怂恿深爱的人放手 提交于 2019-12-19 17:44:42
问题 I have a Sinatra Application enclosed in Sinatra::Base and I'd like to run some code once the server has started, how should I go about doing this? Here's an example: require 'sinatra' require 'launchy' class MyServer < Sinatra::Base get '/' do "My server" end # This is the bit I'm not sure how to do after_server_running do # Launches a browser with this webapp in it upon server start Launchy.open("http://#{settings.host}:#{settings.port}/") end end Any ideas? 回答1: Using the configure block

How to access *incoming* headers in Sinatra?

那年仲夏 提交于 2019-12-19 09:44:52
问题 I'm sending a request to a Sinatra application by this: curl -X POST --header "MyHeader: 123444" http://localhost:9292/test -d "" How can I access it in the route? These don't work: headers["MyHeader"] request["MyHeader"] request.env["MyHeader"] They're all nil. 回答1: Have you tried adding HTTP to the header name? So it would be request.env["HTTP_ MyHeader"] This is part of the rack spec. 来源: https://stackoverflow.com/questions/35787395/how-to-access-incoming-headers-in-sinatra