sinatra

Passing variables between routes in Sinatra

不问归期 提交于 2019-12-25 01:46:28
问题 I'm implementing sms-validation of registration on Sinatra site, and I got this code: post '/reg' do phone = params[:phone].to_s code = Random.rand(1000..9999).to_s HTTParty.get('http://sms.ru/sms/send?api_id=' + api_id + phone + '&text=' + code) end This take users phone from post request, than generates 4 digit code, and sends code on number via get request to sms service. But, page doesn't reloading, because at that moment opens modal dialog, where user should type code . Button which

Page Views counter sinatra?

北慕城南 提交于 2019-12-24 21:41:41
问题 How to implement a page views counter in Sinatra and Ruby? I have tried the @@ variables but they reset to zero whenever the page is loaded... Like this one: http://148.251.142.233:8080/ Thanks! 回答1: I think your problem is that you cant store global variable in sinatra as usual. You need to store page views count data in setting like this set :my_config_property, 'hello world' Here is docs about it http://www.sinatrarb.com/configuration.html SO question about it In Sinatra(Ruby), how should

How to include a javascript file with Sinatra using ajax

烂漫一生 提交于 2019-12-24 19:28:36
问题 Note: This works fine when I don't use ajax. I have the same behavior with slim and haml. Here is the source for using ajax with Sinatra I am trying to run some javascript in a page created using sinatra while using ajax. See sample using haml below. This works fine. Is there any way I can use a file containing javascript, instead of the alert statement below, i.e,. use alert.js @@testjavascript %p #{@time} :javascript alert("Hello world"); The following is just to give additional background

Efficient way to render ton of JSON on Heroku

ε祈祈猫儿з 提交于 2019-12-24 14:45:43
问题 I built a simple API with one endpoint. It scrapes files and currently has around 30,000 records. I would ideally like to be able to fetch all those records in JSON with one http call. Here is my Sinatra view code: require 'sinatra' require 'json' require 'mongoid' Mongoid.identity_map_enabled = false get '/' do content_type :json Book.all end I've tried the following: using multi_json with require './require.rb' require 'sinatra' require 'multi_json' MultiJson.engine = :yajl Mongoid.identity

Running a modular Sinatra app with Thin and EventMachine. It starts twice?

蹲街弑〆低调 提交于 2019-12-24 14:26:48
问题 I have a modular Sinatra web app running using Thin, with EventMachine running additional tasks. It works, but there's something a bit odd about the webserver: Any requests, whether successful or 404s, don't appear in the log output from Thin/Sinatra. And when I cancel the process, the server ends twice. Here's the rough, basic structure of the app: Procfile: web: ruby app.rb app.rb: require 'thin' require 'eventmachine' require 'app/frontend' EM.run do # Start some background tasks here...

Looping through weeks of the year in Ruby (Sinatra)

﹥>﹥吖頭↗ 提交于 2019-12-24 09:28:43
问题 I'm creating a very simple timeshare application using Sinatra and Datamapper. Every user in the application will have n reservations and for the time being each reservation runs from Monday to Sunday and there can only be one reservation per week. Now I will need a view with a textbox (and label) for each week of the year where the users will put their name (through autocompletion or something) and thereby creating a reservation for that week. And if the week is reserved the name will of

Mounting Sinatra app on rails 5

陌路散爱 提交于 2019-12-24 05:45:17
问题 I searched the web and don't know why i am getting this errors... Im trying to mount a Sinatra app that i have to refactor into a rails app so i can do the transition smoothly, so i created a dummy project to test. My routes file: Rails.application.routes.draw do match "/sinatra" => SinatraApp, :anchor => false end Sinatra app: class SinatraApp < Sinatra::Base get "/" do "Hello Sinatra World" end end The Sinatra app is located on the lib directory and it is auto loading correctly, i tried to

How do I properly put embedded ruby code in to JavaScript?

风格不统一 提交于 2019-12-23 17:03:03
问题 I am trying to embed the output of Ruby code in JavaScript: var stuff= "<% Representative.get('http://0.0.0.0:4568/') %>"; The embedded part is working by itself showing a result like this: { "name":"John Johnson", "street":"Oslo West 555", "age":33, "phone":"555 1234567"} The line above is the EXACT PAGE SOURCE; it runs locally though, so I can't show you the page. When in a variable, I try to send it to my application with this: document.getElementById("X_Axis").value=stuff.name; through

Database configuration does not specify adapter (Sinatra + Heroku + Activerecord)

坚强是说给别人听的谎言 提交于 2019-12-23 16:54:49
问题 I'm getting an error (on Sinatra + ActiveRecord Heroku) that Database configuration does not specify adapter . From some research, it looks like this is because Heroku expects there to be no environmental variables used during rackup. I removed the env vars from the db environments file that listed the database URL, but I'm still getting the same error. EDIT: This also worked just a day ago with the db files unchanged, so I'm not sure what could be wrong. 2015-09-01T02:44:40.980448+00:00 app

HAML - a very weird indentation difference - bug?

时光总嘲笑我的痴心妄想 提交于 2019-12-23 13:27:31
问题 This HAML %script{:type => "text/javascript"} :plain $(document).ready(function() { bar(); var foo = foo_func("#{}"); }); as expected gives this: <script type='text/javascript'> $(document).ready(function() { bar(); var foo = foo_func(""); }); </script> But this ALMOST IDENTICAL HAML (changed only bar() to prep() ): %script{:type => "text/javascript"} :plain $(document).ready(function() { prep(); var foo = foo_func("#{}"); }); gives this: <script type='text/javascript'> $(document).ready