sinatra

Calling Sinatra from within Sinatra

I have a Sinatra based REST service app and I would like to call one of the resources from within one of the routes, effectively composing one resource from another. E.g. get '/someresource' do otherresource = get '/otherresource' # do something with otherresource, return a new resource end get '/otherresource' do # etc. end A ...

What is a very simple authentication scheme for Sinatra/Rack

I am busy porting a very small web app from ASP.NET MVC 2 to Ruby/Sinatra. In the MVC app, FormsAuthentication.SetAuthCookie was being used to set a persistent cookie when the users login was validated correctly against the database. I was wondering what the equivalent of Forms Authentication would be in Sinatra? All the authentication...

Serializing a MongoDB grid ID into a string using ActiveRecord

In my Sinatra app, I'm using a MongoDB with Grid to store book covers on Heroku. I want to be able to associate these with the books in my ActiveRecord-driven primary database. Currently, I'm downloading the image from Google Books, storing it in the MongoDB, and storing the BSON::ObjectID object into the database as a string. When I go...

Strange Datamapper's behaviour

I have this code in my controller: @cats = DirCat.all And this in a view: %ul#menu = @cats.each do |item| %li = link_to item.title, "/catalog/#{item.id}/" And get strange output: <ul id='menu'> <li> <a href="/catalog/4/">hello</a> </li> <li> <a href="/catalog/5/">hello 1</...

Sinatra app running on Heroku has RegexpError

My sinatra app runs fine locally but when I push it to heroku it crashes and I get this error RegexpError - undefined (?...) sequence: /(?<=(LIST ALL SELECTED ))\w/: The line of code where the occurs is match = data.match('(?<=(LIST ALL SELECTED ))\w')[0] What I am trying to do is capture the next letter directly after 'LIST ALL S...

RMagick with a direct form submitted Image from Sinatra

I am trying to do something quite simple using Sinatra and RMagick. Take a image, through a simple form file upload Use RMagick to resize it Then store it in a database for persistence (irrelevant) But after going through the RDocs and endless head banging testing I can't seem to get the form image to a RMagick object cleanly. This...

How do I mix Ruby and HTML5 in a Sinatra application?

I am getting information from the browser using Javascript / HTML5 that I want to pass back into Sinatra and Ruby. How can I pass this information back into Sinatra so that I can use it in other parts of my code? ...

Rails 3 vs Sinatra

For my next web application, I'm debating whether to use Rails 3.x or Sinatra. I would like to use the server to provide user authentication, application-triggered emails, a fairly complex data model (behind ActiveRecord), and a JSON data interface with the web client. The client side will use static HTML, static CSS, Javascript/jQuer...

Sinatra hangs seemingly without a reason

I have a strange problem with sinatra... In my app the login form is checking with AJAX live whether a nickname is already taken or free... This works fine 90% of the time... But sometimes, randomly, I get no response from the given route anymore... in the console log all new requests to this route are missing as if I haven't sent anyth...

Sinatra message Queue

Starling is a great (at least for small projects) and simple message queue, however, it doesn't actually manage or start workers that consume the queues. Workling does this for Rails projects, but doesn't work for pure ruby applications, neither for Sinatra. Before I fork workling, or create my own custom one with threads/fork, is there...

Sinatra, Rails and Rack - User/Session Management

Does anyone know of a way to authenticate in a Rails application and allow other Sinatra applications to pass that authentication token and session state through rack? I'm looking for something that basically allows single sign on. (I already have the secret and key in the rails app with authentication, now looking to use that as the si...

Problem with post in Sinatra

I'm using JQuery to post in a Sinatra application. $.post("/addnewlistitem", $('#inputrow1').val(), function(data){alert(data);}); Haml looks like this: %input{:type => "text", :id => "inputrow1", :name => "item", :class => "txt"} And the ruby code, like this: post '/addnewlistitem' do @v = params[:item] end The problem is ...

Streaming data from Sinatra/Rack application

I am trying to stream textual data (XML/JSON) from a Ruby (1.9.1p378) Sinatra (1.0) Rack (1.2.1) application. The suggested solutions (e.g. http://stackoverflow.com/questions/3027435/is-there-a-way-to-flush-html-to-the-wire-in-sinatra) do not seem to work - the server just blocks when I yield elements of some infinite stream (e.g. from %...

Sinatra: executing code on starting or restarting my app

Hi! I want to execute some ruby code on the start of application. Actualy this is some SQL for creating all my tables if they are not already exists. Nowaday I should run my sql manualy (creating new tables ordinary), but I want to write somewhere in my helloworld.rb sql, which will execute sql once my app is started or restarded. Th...

How to render archive-like structure in sinatra of old wordpress posts?

Let's say I scrapped my old wordpress installation and I put the following directories in /public (sinatra application) 2006 2008 2010 category my-work 2007 2009 archives tag The year directories go down in this format: /year/month/day/title-of-post/ Problem 1: I can get /year/month/day/title...

How do I make Rake tasks run under my Sinantra app/environment?

I'm using Sinatra, and I wanted to set up some of the convenience rake tasks that Rails has, specifically rake db:seed. My first pass was this: namespace :db do desc 'Load the seed data from db/seeds.rb' task :seed do seed_file = File.join(File.dirname(__FILE__), 'db', 'seeds.rb') system("racksh < #{seed_file}") end end ...

Ruby Sinatra - connect to mongoDB on mongoHQ failed

Hi all: This is just for my weekend project/study, I am very new to Sinatra and MongoDB. I've installed the gems for mongoDB, such as: mongo, mongo_mapper and mongoid. When I tried connecting to my database on MongoHQ from localhost, it encountered such an error: Mongo::ConnectionFailure at / failed to connect to any given host:port ...

Ruby MongoDB- how to sort records based on datetime?

Hi all: I must have done it in a wrong way: the records printed out are out of order, even though they are inserted into db one at a time. Here is the code: get '/' do db = Mongo::Connection.new("localhost", 27017).db("testdb") @notes = db.collection('notes') @notelist = Set.new() @notes.find().each{|record| @notelist.add(recor...

How to make Sinatra work over HTTPS/SSL?

As the title says... Google doesn't give anything useful concerning this. How do I set up and configure https/ssl for Sinatra apps? How to create a https route? etc. I have never used https for my apps before and have no experience tweaking Rack/whatever, so I appreciate detailed answers... ...

User management using sinatra

Hi, I need to make a basic user management system for my application using Sinatra but I'm not sure how I should think about it. It needs to: Register User Login User How should I think about it? This shouldn't be hard, I'm just very new to all this. Thank you. ...