sinatra

How to specify custom Sass directory with sinatra

Instead of serving my Sass files from the default 'views' directory I'd like to change this to /assets/sass The following attempts are in my main ruby root file in the app: Attempt 1 set :sass, Proc.new { File.join(root, "assets/sass") } get '/stylesheet.css' do sass :core end With this I get the following error: myapp.rb:17 ...

Sinatra programatically get port and other information about service

I have a sinatra service foo.rb To run it I on a different port I would type "ruby foo.rb -p 5000". While the program is running I would like to be able to get the port (in this case 5000) and other information. Is there a way to get info like this while the app is running? Thanks ...

From Sinatra Base object. Get port of application including the base object

I have a Sinatra::Base object that I would like to include in all of my web apps. In that base class I have the configure method which is called on start-up. I would like that configure code to 'register' that service with a centralized database. The information that needs to be sent when registering is the information on how to contac...

How to create a link in Sinatra that points to a directory of files?

I have an application that calls an other application that populates a directory. Once it is finished I want to provide a link to the directory that contains the created files and people can examine or download them via the browser: For example this works to provide a link to a single file: (Note this uses HAML) but the idea is the sam...

deploy a sinatra app with passenger gives only 404, page not founds. Yet a simple rack app works.

I have correctly (or prbably not) installed passenger on apache 2. Rack works, but sinatra keeps giving 404's. Here is what works: config.ru: #app = proc do |env| return [200, { "Content-Type" => "text/html" }, "hello <b>world</b>"] end run app Here is what works too: Running the app.rb (see below) with ruby app.rb and then looki...

trying to use ActiveRecord with Sinatra, Migration fails question

Hi, running Sinatra 1.0, I wanted to add a database table to my program. In my Rakefile I have a task task :environment do ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))["development"]) end I have a migration task in my namespace that calls the migration code: namespace :related_...

image url helper for sinatra?

I'm looking for an image url helper for sinatra that allows me to do something similar to staticmatic's, where I can shortcut to a relative path like so... =img "me.jpg" Can anybody point me in the direction to where this might be online, or where I could learn how to write one, or provide an example of one they have already written ...

Get absolute (base) url in sinatra.

Right now, I do a get '/' do set :base_url, "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}" # ... haml :index end to be able to use options.base_url in the HAML index.haml. But I am sure there is a far better, DRY, way of doing this. Yet I cannot see, nor find it. (I am new to Sinatra :)) Somehow, outside of...

Sinatra not passing header with redirect

Hi All I have a simple Sinatra proxy, which when an endpoint is called, will redirect to another endpoint on the same Sinatra proxy. When I make a request with a header, the proxy doesn't seem to pass this header through to the second endpoint when the request redirects in the first. This is my code: get '/first' do # g...

Any non-rails ruby forum application out there?

I have a rather complete application based on sinatra. I feel in need for an easy to integrate forum module (code, extension, etc.). Running a parallel Rails application is not an option on my tiny VPS plan (I even use redis to keep a small footprint). A sinatra based forum would be great news. Thanks ...

Inheritance in Ruby / Sinatra

Hi, I'm working on a ruby project using Sinatra as a framework and have a question about extending classes. Lets say I have a User class which is extended by an Admin, does the Admin have to be defined in User.rb? I've tried putting it in Admin.rb but I get an error saying: admin.rb:1: uninitialized constant User (NameError) Thanks....

Set date format in ruby model (sinatra/datamapper)

Hi, I have a ruby model that contains a date attribue which I'd like to be able to pass in as a parameter in the format dd/MM/yyyy. However, my sqlite3 db stores the data in yyyy-MM-dd format so when a date like 20/10/2010 gets passed in, it will not be read to the database. I am using the Sinatra framework and using haml for the mark...

NoMethodError using Memcached Sinatra-style

I've just installed Memcached on my Mac and updated my Sinatra app configuration as described in Heroku's documentation, but I'm getting a NoMethodError when trying to use the hash-based syntax they specify: >> CACHE['color'] = 'blue' >> CACHE['color'] Using explicit get and set methods as below seems to work fine. >> CACHE.set('colo...

Could someone give me an example of node.js application

Guys, I'm trying to understand the differences between some of the newer web programming frameworks that now exists, namely Node.js, Rails, and Sinatra. Could someone give me an example of applications that would work best on each of the frameworks? That is to say, what is an application that would be best suited for Node.js as oppose...

In Sinatra, best way to serve iPhone layout vs. normal layout?

I'm writing a Sinatra app which needs to render different layouts based on whether the user is using an iPhone or a regular browser. I can detect the browser type using Rack-Mobile-Detect but I'm not sure of the best way to tell Sinatra which layout to use. Also, I have a feeling that how I choose to do this may also break page caching....

Scaffolding Extensions: NoMethodError

Not sure if many people are familiar with Scaffolding Extensions for Ruby, but I've looked through their docs, forums, and even the source code of the Heroku test site, and not found an answer. I made a basic Sinatra app and followed right from the RDoc's instructions: require 'scaffolding_extensions' require 'sinatra/base' class Thing...

Cropping image with ImageScience

ImageScience is cool and light. I am using it in my sinatra app. But I can't understand how can I crop image with not square form and how can I make thumbnail with two dimensions. As I found on ImageScience site: ImageScience.with_image(file) do |img| img.cropped_thumbnail(100) do |thumb| thumb.save "#{file}_cropped.png" end ...

Where am I going wrong? "undefined method 'application' for Sinatra:Module" Sinatra/Passenger/Apache

Hi, I'm trying to get my first Sinatra app off the ground, but am getting an error page from Passenger: undefined method `application' for Sinatra:Module Here's my Rackup file: require 'rubygems' require 'sinatra' set :env, :production disable :run require 'app' run Sinatra.application And the app itself: #!/usr/bin/env ruby re...

How can I simplify my nested sinatra routes?

I require nested subdirectories in my sinatra app, how can I simplify this repetitive code? # ------------- SUB1 -------------- get "/:theme/:sub1/?" do haml :"pages/#{params[:theme]}/#{params[:sub1]}/index" end # ------------- SUB2 -------------- get "/:theme/:sub1/:sub2/?" do haml :"pages/#{params[:theme]}/#{params[:sub1]}/#{...

Send and Receive JSON using RestClient and Sinatra

Hi, I am trying to send a JSON data to a Sinatra app by RestClient ruby API. At client(client.rb) (using RestClient API) response = RestClient.post 'http://localhost:4567/solve', jdata, :content_type => :json, :accept => :json At server (Sinatra) require "rubygems" require "sinatra" post '/solve/:data' do jdata = params[:data...