sinatra

when to use before filters and about to organize code (DRY)

Hi, I have coded some Ruby script to scrap some web data; then I merged that script with a small Sinatra application to "publish" some rest methods to fetch reports... My Sinatra app is making a request to Nagios3 and navigate through some forms (3 steps in fact), this is just working fine. Then under step3, I "press" the submit button...

Setup Padrino with DataMapper and MySQL database

Hello I am trying to setup a Padrino project using DataMapper and MySQL on my Mac OSX Snow Leopard. I have the necessary gems: dm-core data_objects do_mysql mysql (linked to my original Mac OSX installation) But when I try to start the padrino with PADRINO START from the console, I get the following error: /Users/ivolution/.bundle/rub...

Strange DataMapper (0.10.2) error. Please help!

See the full error here: http://notesapp.heroku.com/ I'm using DataMapper and dm-validations 0.10.2. No matter how much I tweak my models, I get the same error, or another one. Here's how my model looks like: class User include DataMapper::Resource attr_accessor :password, :password_confirmation property :id, Serial, :req...

NameError at / uninitialized constant Sass::SyntaxError

I am using Padrino and when I try to specify my application.sass file I get this error NameError at / uninitialized constant Sass::SyntaxError I thought I might have something missing, so I checked out the sample_blog application at their GIT to verify my SASS is working correct. It was working correct and the blog app was running fine....

In Sinatra, how can I serve static index.html files in subdirectories in public folder?

I noticed that Sinatra does not recognize index.html files in public folder's subdirectories and returns an error when url is pointing to a directory without specifiying the file name. For example, if user enters a url like "www.mydomain.com/subdiretory/", Sinatra fails to recognize the existence of an index.html file in that directory....

How to stream image object in Sinatra

I had uploaded images to mongoDB using GridFS. I want to retrieve an image from the db and display it in the browser. How to do this with the help of Sinatra and HAML. ...

How do I make Rack::Reloader re-load changes to haml files?

My jruby rack sinatra compass haml app correctly reloads changes to *.rb files, but does not detect changes to *.haml files. Is this compass doing some caching or a limitation of Rack::Reloader? Any pointers to how to fix? ...

Sharing a database connection with included classes in a Sinatra application

I'm converting a part of a rails application to its own sinatra application. It has some beefy work to do and rather than have a million helps in app.rb, I've separated some of it out into classes. Without access to rails I'm rewriting finder several methods and needing access to the database inside of my class. What's the best way to...

Rendering sass template from a sinatra app doesn't work. Is this due to v.1 incompatibility? Workaround?

get '/stylesheets/style.css' do header 'Content-Type' => 'text/css; charset=utf-8' sass :style end does not produce the stylesheet anymore. What would be a version 1.0 compatible way to do this? Or, troubleshooting suggestions if you think that the issue is with the code? The style.sass file is in the /views folder. Haml files fr...

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

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. ...

Is it possible to run locally JRuby on Google App Engine without restarting server on every change?

Unfortunately, GAE requires restart of the server on each code change. Is it possible to prevent it and have immediate feedback after code save? Or, can I import Google App Engine's API into my ruby code and run it on Sinatra server? Tried this but it fails on "import com.google.appengine.api" (it doesn't know what 'com' is). For Sinat...

Passing parameters thru Ruby's OAuth

I'm using Mirven's Twitter OAuth Sinatra example and trying to figure out how I can send a 'next page' parameter with the Oauth request: ie. The user attempts to visit /edit/profile which requires a login so I redirect to /request which deals with login via twitter - I now want to be able to redirect the user to the address they were or...

Sinatra Title Slugs

I'm trying to create a slug helper in Sinatra. Here's the code (as seen here): helpers do def sluggify(title) accents = { ['á','à','â','ä','ã'] => 'a', ['Ã','Ä','Â','À'] => 'A', ['é','è','ê','ë'] => 'e', ['Ë','É','È','Ê'] => 'E', ['í','ì','î','ï'] => 'i', ['Î','Ì'] => 'I', ['ó','ò','ô','ö','õ'] => 'o', ...

What is a better way to convert a simple sinatra app to static html pages?

A friend of mine asked to create a static website and I found that making such site using Sinatra is a pure joy. I just wrote all my routes like this: get '/index.html' do haml :index end get '/app.css' do sass :app end .... So I was able to use layouts, and haml and sass to put site together quickly. To create the static site ...

File upload with Sinatra.

I am trying to be able to upload files with Sinatra. I have the code here, but I'm getting the error "method file_hash does not exist" (see /lib/mvc/helpers/helpers.rb). What is going on here? Is there some dependency I'm missing. ...

How do I serve nested static content on Heroku?

I have a rails application with static content in the public directory (e.g. public/index.html) and additional static content in nested subdirectories (e.g. public/one/two/index.html). All the static content is served correctly if I run it locally via script/server but when I upload it to Heroku the top-level page loads correctly but t...

Sinatra: How do I provide access to a login form while preventing access to the rest of my Sinatra app?

I recently created a Sinatra app with a login form (no basic auth). To prevent access to the app unless the user logged in I put a before block in place before do unless request.path_info == '/login' authenticated? end end I quickly realized that this prevented me from accessing resources in the public directory like my style...

How do I pass a cookie to a Sinatra app using curl?

I'm using the code from the example titled "A Slightly Bigger Example" from this tutorial http://rubylearning.com/blog/2009/09/30/cookie-based-sessions-in-sinatra/ to figure out how to send a cookie to a Sinatra application but I can't figure out how to set the values correctly When I set the name to be "brandon" in the application it c...

Thin, Sinatra, and intercepting static file request to do CAS authentication

I'm using the casrack-the-authenticator gem for CAS authentication. My server is running Thin on top of Sinatra. I've gotten the CAS authentication bit working, but I'm not sure how to tell Rack to intercept "/index.html" requests to confirm the CAS login, and if the user is not allowed to view the page, return a HTTP 403 response inst...

Passing data between blocks using sinatra

Hi All I'm trying to pass data between blocks using sinatra. For example: @data = Hash.new post "/" do @data[:test] = params.fetch("test").to_s redirect "/tmp" end get "/tmp" do puts @data[:test] end However whenever i get to the tmp block @data is nil and throws an error. Why is that? ...