sinatra

Upload large files using Ruby

I'm wondering what is the best pattern to allow large files to be uploaded to a server using Ruby. I've found Rails and Large, Large file Uploads: Looking at the alternative but it doesn't give any concrete solutions. I don't want to use Rails since I'm working on a simple upload server that'll run in standalone mode. I'm guessing tha...

Why am I getting Net::SMTPSyntaxError?

I am trying to set up a Sinatra based Ruby app to connect to Gmail and send emails through SMTP. I followed the instructions I found on the web, but I always get this error: Net::SMTPSyntaxError at /contact 502 5.5.1 Unrecognized command. k30sm7454901vbl.19 * file: smtp.rb * location: check_response * line: 930 It's being raise...

Make space to dash with regexp

I've got a sinatra app where I plan to make a friedly-urls on the fly. I've got a function with a regexp that looks like this, but it won't turn 'spaces' into 'dashes', ' ' to '-'. def self.make_slug(title) title.downcase.gsub(/ /, '-').gsub(/[^a-z0-9_]/, '').squeeze('-') end Thanks in advance! Update Now I'm also trying to change...

Benefits of Sinatra for a web service like controller

I am writing a simple ruby controller that just needs to respond as a webservice to a bunch of mobile clients. Someone told me I should look into Sinatra. What is the point of using Sinatra for something this simple? He mentioned that it would be "faster" but how can a wrapper on top of something make it faster? I don't want to overco...

Need caching techniques for REST service calls

I am building a Ruby on Rails application where I need to be able to consume a REST API to fetch some data in (Atom) feed format. The REST API has a limit to number of calls made per second as well as per day. And considering the amount of traffic my application may have, I would easily be exceeding the limit. The solution to that would...

Simple Ruby Input Validation Library

I've been looking all over the place for a simple input validation library for Ruby. Everything seems to point towards ActiveRecord (or similar). I'm not using Rails, I'm using Sinatra without an ORM. What's the best approach for validating user input (without tying directly to the model layer)? Simple things like "string length", "is nu...

Automatically encode Rack output with JSON when Content-Type is application/json

I've got a modular Sinatra app and I'd like to encode the output as JSON when the content-type dictates. At the moment I'm doing so manually in my routes: get 'someroute' do # content-type is actually set with a before filter # included only for clarity content_type 'application/json', :charset => 'utf-8' # .. # {:su...

Get Cucumber to use the test environment in Sinatra

This seems right, but doesn't seem to work. env.rb: class MyWorld set :environment, :test end app.rb: configure :development do DataMapper::setup(:default, "sqlite3://development.sqlite3") end configure :test do DataMapper::setup(:default, "sqlite3://test.sqlite3") end It keeps using the development environment. Am I missin...

Sinatra, Bundler and BUNDLE_PATH confusion

I am having trouble configuring Sinatra to use Bundler. I am confused as to where Gems should be being installed? I've read both this question and this documentation. My Gemfile looks like: source "http://rubygems.org" gem "sinatra" gem "amazon-ec2" My config.ru looks like: require "rubygems" require "bundler" Bundler.setup require ...

Datamapper - Find each client by project

Hi, I'd like to view each Project by Client, but unsure how to use Datamapper to get this information out. I have my relationships setup like this: class Client property :id, Serial property :name, String has n, :projects, :foreign_key => "company_id" end class Project include DataMapper::Resource property :id, Serial...

How to do an if/else in HAML without repeating indented code

Depending on if a user is signed in or not, I'd like to print a different kind of %body-tag. This is how I currently do it: - if defined? @user %body(data-account="#{@user.account}") %h1 Welcome -# all my content - else %body %h1 Welcome -# all my content As you can see there's a lot of duplicated code in there. H...

Sinatra - API - Authentication

Hi All, We going to develop a little API application in Sinatra. What are the authentication options available to secure the API calls? Thanks, Imran ...

Ruby / Sinatra - serving up css, javascript, or image files

What is the correct way to route your request through Sinatra so that it serves up the file with no processing? I'm looking for the most common way people do this in the Sinatra framework? I normally place all of my static content in a "content" path. examples: /content/css /content/img /content/js How can I use a wildcard to serve...

rack duplicates every log message

When I test a Sinatra app on my local box with rackup, every log message appears twice. How can I get them to appear only once? ...

Sinatra, select from Datamapper pass to Haml

I'm doing a brief exercise, condensed below. The issue I'm having is that I'm able to pass a selection of all tickets, but not a selection of one ticket. At / there is no problem listing all the tickets, at endpoint for a ticket I get: NoMethodError at /pi2l9ulnw undefined method `slug' for # I'm relatively new to Ruby and cutting and ...

View specific stylesheets in Sinatra (by naming convention)

I would like to have my Sinatra app include a view specific stylesheet in the layout. Consider this simple app: app_folder_root/ | my_app/ | my_app.rb | public/ | css/ | index.css | layout.css | views/ | index.haml | layout.haml config.ru config.ru: require 'rubygems' require './my_app/my_app' map '/' do run MyApp...

Datamapper, Sinatra, Haml : attaching and rendering Comments from a post

I have a model Ticket which has n Comments belonging to it (many to one relationship). The issue is that I can not render any of the comments nor does the form post the comments to the database. I can kinda sorta do this from irb. I can add comments to tickets.comments, but I cannot pull individual comments - I can pull up the collect...

Why is my OpenId authentication failing?

I'm porting my OpenId authentication scheme from Sinatra to Rails 2.3.8. Everything works well up until I get the response back from my OpenId provider. The Response object I get back is an OpenId::Consumer::FailureResponse, when it should be a SuccessResponse. I ported this directly from Sinatra, and the only difference is what sessio...

Forbidden message when serving a sinatra local site using nginx passenger.

Hi, I've followed the instructions for installing phusion passenger with nginx in ubuntu. I had some issues while installing since I use rvm and I had to install as root and the installer was failing to find rake so i temporarily chmoded /opt to be owned by my user and after installation I resetted ownership to root. I can see nginx welc...

Sinatra PUT method not working?

For some reason, my "PUT" method isn't caught by Sinatra using this html. Can someone help me spot the mistake? When I use a "post" action in my controller, it works just the way it is expected... <form method="post" action="/proposals/<%[email protected]%>/addItem"> <input type="hidden" name="_method" value="put"/> <div> <label for="it...