sinatra

How to add two parameters from the url

有些话、适合烂在心里 提交于 2019-12-11 22:17:23
问题 How can I display in my web page the result of int1 + int2 ? And can I know if it's an integer or a string? Here is my code: require 'sinatra' get '/add/:int1/:int2' do puts #{params[:int1]} + #{params[:int2]} end 回答1: "#{params[:int1].to_i + params[:int2].to_i}" 回答2: you need to pass it in url http://yourdomain/add/2/3 #=> this will display 5 :int1 => 2, :int2 => 3 for embedding/interpolating variables use double quotes with puts puts "#{params[:int1]} + #{params[:int2]}" 回答3: Here is

How do I access a web page from Sinatra?

淺唱寂寞╮ 提交于 2019-12-11 18:31:54
问题 I want to run this PHP script http://db2express/imacs/radek/3.1/rationalTest.php?mode=create from Sinatra. Sinatra runs on a different box. Is there any Sinatra built-in way how to do that? I know I can use mechanize , just wondering if there is something else to use? 回答1: Open-URI will do a good job if all you need to do is retrieve the content of the URL or tickle some job at the other end of the URL. If you need more control then Net::HTTP or Typhoeus are available. Both Open-URI and Net:

In Sinatra, is there a way to forward a request to another app?

霸气de小男生 提交于 2019-12-11 15:36:25
问题 I'm trying to do something like this: class Dispatcher < Sinatra::Base def initialize @foo = Foo.new end get '/foo/*' do @foo.call(params[:splat]) end end So that URL /foo/abc/def?xxx=yyy would be like calling the Foo app with /abc/def?xxx=yyy. This seems like it should be easy, but I haven't seen any example of it. 回答1: I ended up doing this in a Rack config.ru file: map "/abc" do run Foo.new('abc') end map "/def" do run Foo.new('def') end Not exactly what I wanted, but saves me from

jquery-ui autocomplete works locally not on heroku

自古美人都是妖i 提交于 2019-12-11 12:42:55
问题 I am using jquery-ui's autocomplete on two input fields of an HTML form in a Sinatra app. They work on my local machine but not on Heroku. Jquery-ui's datepicker works on this same page, so I know the jquery and jquery-ui javascript files are being loaded correctly. Also, I can see that the variable that I am using as the source for the autocomplete is actually getting populated from the database. There are no console errors as well. Here's the HTML: <form action="/add-event" method="post">

REST API : with Apache http web/content server Sinatra Passenger app server

我的未来我决定 提交于 2019-12-11 12:27:10
问题 I am totally newbiew to REST API and from all reading, got a little bit hands on with Sinatra as it looks really simple in terms of the syntax. However i am a little bit confused as to how a entire 3 tier set up with http web server and app server work. I am planning to learn by writing a simple web application which goes a little more than "hello world" . My setup I have 2 html page lets say a.html and b.html. a.html is my home page and I set it in htdocs i.e using Apache. In a.html i click

From Sinatra Base object. Get port of application including the base object

梦想与她 提交于 2019-12-11 11:53:59
问题 I have a Sinatra::Base object that I would like to include in all of my web apps. In that base class I have the configure method which is called on start-up. I would like that configure code to 'register' that service with a centralized database. The information that needs to be sent when registering is the information on how to contact this web-service... things like host and port. I then plan on having a monitoring service that will spin over all registered services and occasionally ping

Ruby Sinatra with consumer thread and job queue

淺唱寂寞╮ 提交于 2019-12-11 11:23:51
问题 I’m trying to create a very simple restful server. When it receives a request, I want to create a new job on a queue that can be handled by another thread while the current thread returns a response to the client. I looked at Sinatra, but haven't got too far. require 'sinatra' require 'thread' queue = Queue.new set :port, 9090 get '/' do queue << 'item' length = queue.size puts 'QUEUE LENGTH %d', length 'Message Received' end consumer = Thread.new do 5.times do |i| value = queue.pop(true)

Ctrl+C not killing Sinatra + EM::WebSocket servers

纵然是瞬间 提交于 2019-12-11 11:16:35
问题 I'm building a Ruby app that runs both an EM::WebSocket server as well as a Sinatra server. Individually, I believe both of these are equipped to handle a SIGINT. However, when running both in the same app, the app continues when I press Ctrl+C. My assumption is that one of them is capturing the SIGINT, preventing the other from capturing it as well. I'm not sure how to go about fixing it, though. Here's the code in a nutshell: require 'thin' require 'sinatra/base' require 'em-websocket'

Not able to display Month names on Rickshaw Graph on Coffeescript

倖福魔咒の 提交于 2019-12-11 11:14:47
问题 I am working on a project using Sinatra based framework called Dashing. Part of my project is to create a graph using RickShaw Graph. My problem is that I am not able to display month names and dates on the X-Axis. I am using coffeescript to render these values. Here is the code for the graph: class Dashing.Graph extends Dashing.Widget @accessor 'points', Dashing.AnimatedValue @accessor 'current', -> return @get('displayedValue') if @get('displayedValue') points = @get('points') if points

How should I store twitter token so users don't have to go to twitter_oauth everytime?

南楼画角 提交于 2019-12-11 11:07:24
问题 I'm developing twitter application so I'm using twitter_oauth gem to authorize. Here's the code which is very basic one. So, if a user goes to /login it will redirect user to twitter login, once he logged in and click authorize the app, the he will be redirected back to my website. begin callback = ENV['twitter_callback'] || "http://127.0.0.1:4567/login/success" request_token = @twitterClient.request_token(:oauth_callback => callback) MemcacheUtil::set("request_token_twitter", request_token,