sinatra

Save all user entries from html text built off a loop using ruby and sinatra

早过忘川 提交于 2019-12-01 08:23:45
问题 I am creating a web page that displays a table. It also has four columns at the end of each record that are text fields where the user can enter data. When the user hits the submit button at the bottom I want to save all the data in all the text fields and add it to my table. How can I save the data for all the text fields? Here is my code. <h1>Testing Table</h1> <form action="/table/" method="POST"> <table> <thead> <tr> <% event_column.each do |header| %> <th> <%= header %> </th> <% end %> <

Access current git commit number from within Heroku app

痞子三分冷 提交于 2019-12-01 08:08:30
I know the slug compiler removes the .git directory when creating a heroku slug, but is there any way to configure Heroku so that I can access the currently running git commit number from within my scripts? I'd like to be able to have a small link on my sinatra app (run within Heroku) which says "running version e72fb274a0 " (or something similar). How can I retrieve this, or force the slug compiler to add it to an environment variable? PROGRESS: I reckon the best way to do this is to make a custom buildpack which writes the git commit version number to the heroku slug before the .git

Access current git commit number from within Heroku app

爷,独闯天下 提交于 2019-12-01 06:49:16
问题 I know the slug compiler removes the .git directory when creating a heroku slug, but is there any way to configure Heroku so that I can access the currently running git commit number from within my scripts? I'd like to be able to have a small link on my sinatra app (run within Heroku) which says "running version e72fb274a0" (or something similar). How can I retrieve this, or force the slug compiler to add it to an environment variable? PROGRESS: I reckon the best way to do this is to make a

Ruby Rack: startup and teardown operations (Tokyo Cabinet connection)

半城伤御伤魂 提交于 2019-12-01 06:02:20
问题 I have built a pretty simple REST service in Sinatra, on Rack. It's backed by 3 Tokyo Cabinet/Table datastores, which have connections that need to be opened and closed. I have two model classes written in straight Ruby that currently simply connect, get or put what they need, and then disconnect. Obviously, this isn't going to work long-term. I also have some Rack middleware like Warden that rely on these model classes. What's the best way to manage opening and closing the connections? Rack

Changing HTTP status message using Sinatra

陌路散爱 提交于 2019-12-01 04:11:18
问题 I'm writing a simple Sinatra app, and given a user posts a request with an specific data, I want to return an error '453' (custom error code) with a message CLIENT_ERROR, or something similar. The problem is: looking into the Sinatra documentation and doing some testing I couldn't find a way to setup the response error message, only the response status. So, if a set the Sinatra response get '/' do response.status = 453 end I get the error code right: curl -v localhost:4567 * About to connect(

Should I be using Rails or Ruby for this website application? How?

陌路散爱 提交于 2019-12-01 02:10:43
问题 I'm very new to web programming (or actually, very old to it, since the last time I messed with the web was HTML 1.1), but now need to deploy a web application quickly. It seems like every time I turn around, there's new acronyms and technologies to learn (JSON, XMLRPC, GWT, Javascript, Rails, etc). Here's what my app must do: Given a username and password, authenticate (easy enough, everything does that, apparently). Allow the user to upload a large glob of data for processing. Process that

Start and call Ruby HTTP server in the same script

白昼怎懂夜的黑 提交于 2019-12-01 01:44:27
I wonder how I could start a Ruby Rack application (such as Sinatra) and call it with Net::HTTP or similar in the same script. Of couse I could do something like... require 'sinatra/base' require 'net/http' t = Thread.new do class App < Sinatra::Base get '/' do 'Hi!' end end App.run! :host => 'localhost', :port => 1234 end sleep 2 puts Net::HTTP.start('localhost', 1234) { |http| http.get('/') }.body t.join puts 'Bye!' ...but it doesn't feel optimal to sleep for two seconds, waiting for Thin to start. What I need is some kind of callback when the server has started or does anybody have any

Parsing LESS options in a Sinatra app

混江龙づ霸主 提交于 2019-12-01 00:26:23
I'm having trouble changing the path that LESS uses to include imports. My routes file has get "/css/main.css" do less :main, :paths => ["public/css"] end However, if I include an external less file with @import in my stylesheet the LESS compiler cannot find the file. I've placed a copy in both the views path and public/css directories, but it still can't find it. It CAN however find plain .css files in public\css . I hit this today, and was able to solve it like so: require 'less' require 'sinatra/base' class App < Sinatra::Base # Make LESS @import statements work Less.paths << settings.views

Multipart response in Ruby/Rack

笑着哭i 提交于 2019-12-01 00:02:10
I want my server to send a multipart response (multipart/x-mixed-replace). I'd prefer some kind of solution using the Sinatra framework or a generic Rack app, but any example in ruby would be nice. Here's the equivalent of what I'm trying to do, in PHP: <?php header('Content-type: multipart/x-mixed-replace;boundary="rn9012"'); print "--rn9012\n"; print "Content-type: application/xml\n\n"; print "<?xml version='1.0'?>\n"; print "<content>First Part</content>\n"; print "--rn9012\n"; flush(); sleep(5); print "Content-type: application/xml\n\n"; print "<?xml version='1.0'?>\n"; print "<content

What ORM to use in one process multiple db connections sinatra application?

风格不统一 提交于 2019-11-30 21:45:41
Checked ActiveRecord, DataMapper, Sequel: some use globals (static variables) some require open db connection before loading source file with models. What ORM is better to use in sinatra application that uses different databases. DataMapper is designed for multi-database use. You can set up multiple repositories just by saying something like DataMapper.setup(:repository_one, "mysql://localhost/my_db_name") . DataMapper then tracks all the repositories that have been setup in a hash that you can reference and use for scoping: DataMapper.repository(:repository_one){ MyModel.all } (The default