I want to be able to get Sinatra views from sub-directories of ./views (such as ./views/admin). I know you can set the views like so:
set :views, Proc.new { File.join(root, "templates") }
But how would I be able to set this for only part of the file?
...
Hi,
After asking this question, I started using Sinatra as a way to serve web pages.
This evening, a friend of mine and I started to test the speed of the server.
The file to log in looks like:
require 'rubygems'
require 'sinatra'
require 'haml'
enable :sessions #for cookies!
get '/' do
haml :index
end
And the index.haml look...
Take the following code:
### Dependencies
require 'rubygems'
require 'sinatra'
require 'datamapper'
### Configuration
config = YAML::load(File.read('config.yml'))
name = config['config']['name']
description = config['config']['description']
username = config['config']['username']
password = config['config']['password']
theme = config[...
I have an application class
class MyApplication < Sinatra::Base
# ... do something ...
end
and a config.ru file
# ... load libraries ...
run MyApplication
I usually use Passenger as my development environment which works perfectly fine for a normal – non-modular – Sinatra application. But in this case I have no error output inste...
Hi,
I'm trying to use the Friendly ORM in combination with Sinatra for a small side project, but I'm having trouble implementing a DISTINCT type pattern.
Here is an example of the model class:
class Game
include Friendly::Document
attribute :user_id, Friendly::UUID
attribute :friendly_team, String
attribute :opposing_team, String
a...
I have a combined Sinatra/Rails app that shares a session using Rack::Session::Cookie. The app works fine when started with Rack::Handler::Thin.run app, but if the rackup file is start with thin start, I get an error in Rack::Session::Cookie:
!! Unexpected error while processing request: no marshal_dump is defined for class Proc
no mar...
I want to deploy an app using Sinatra on Phusion Passenger w/ nginx. If I want to set the Expires header on my static content - stylesheets, say - there are appear to be three places where I could accomplish this.
In my Sinatra app, using the API
With Rack middleware
In the server config for my deployment
Which of these methods is t...
This works, but it was a stab in the dark. I know little Ruby.
What's the accepted way to serve a plain old file for a given resource?
get '/xyz' do
File.read 'abc.html'
end
...
Disclosure: I know nothing about web programming
Background to problem:
I have an environmental testing chamber testing embedded computers at various temperatures. It is controlled by a windows application. I can control the chamber via ruby and the Win32API interface of the control application. The chamber is far from my office and I w...
For the following code, why does only "World" gets printed
get '/' do
"Hello"
"World"
end
...
I have a small web-server that I wrote with Sinatra. I want to be able to log messages to a log file. I've read through http://www.sinatrarb.com/api/index.html and www.sinatrarb.com/intro.html, and I see that Rack has something called Rack::CommonLogger, but I can't find any examples of how it can be accessed and used to log messages. ...
Hi,
I'm using the amazon-product-advertising-api gem and am following the example code to try and grab music album data.
The code I have is as follows:
post '/mash' do
username = params[:username]
user = Scrobbler::User.new(username)
@recommendations = user.recommendations
@urls = { }
@recommendations.each do |t...
Hey,
In a little Sinatra app I'm working on, I want to store what I write in a textarea into a text file. What's the simplest way to do this?
...
I have a very simple sinatra site that I'm trying to access via ajax through jQuery.
To keep things incredibly simple, this code snippet:
get '/behavior_count' do
"60"
end
which returns "60" in the browser, shows up as an empty string when attempting to access the site via $.get in jQuery. The strange part is in Firebug, while the...
Using the following Sinatra app
get '/app' do
content_type :json
{"params" => params}.to_json
end
Invoking:
/app?param1=one¶m2=two¶m2=alt
Gives the following result:
{"params":{"param1":"one","param2":"alt"}}
Params has only two keys, param1 & param2.
I understand Sinatra is setting params as a hash, but it does not r...
I'm in the process of learning Sinatra and DataMapper. To do so, I've been playing with a "customer database" project.
Creating and deleting records is trivial and now I'm working on editing records. So far I've managed to piece together a form in my views and a couple of routes that I thought would edit a record. Here's some code ...
Hi! I'm writing a simple application with Sinatra and Datamapper in Ruby and I have a trouble — when I try to save data into my SQLite database nothing is changing. But when I try to install database or change data from irb it works perfectly.
Here is my Datamapper's setup, model and database installing method (this works fine):
DataM...
Hi
In sinatra's app,
require 'rubygems'
require 'sinatra'
require 'haml'
get '/new' do
haml :new
end
get '/edit' do
haml :edit
end
__END__
@@ layout
%html
%head
%title
%body
= yield
@@ _form
# partial form
@@ new
%h1 Add a new item
# require partial _form
@@ edit
%h1 Edit an existing item
# require partial _form
...
I'm playing around with Rails & Sinatra, and I want to execute commands on the server. Those commands are entered from a form. The thing is, if I enter a command which expects input, my whole app hangs. Here's the code I'm using to execute them:
@threads << Thread.new do
Thread.current["buffer"] = ""
puts "starting #{params[:com...
That is to say, let's say I'm writing something that's hosted on foo.com. I'd like it to be possible for a user who goes to foo.com/bar.com to be served up bar.com from foo.com and to be able to interact with bar.com (e.g. navigate to foo.com/bar.com/baz via point-and-click). I understand that this is what a proxy is supposed to do. I...