... mostly about Ruby and Rails...

Donnerstag, 25. Juni 2009

Howto use Sinatra in Rails Metal

just to let everybody know how easy it is to use Sinatra inside Rails 2.3:

# use the Metal generator to generate
./script/generate metal sinatra_test

# add the sinatra gem as a dependency in envirenment.rb
config.gem 'sinatra'

# inside app/metal/sinatra_test.rb remove the SinatraTest class and use the following
class SinatraTest < Sinatra::Application
get '/test' do
content_type :text
status 200
"Hello World from Sinatra"
end
end


that's it... really easy

and even better to just test the sinatra part, run:
rackup app/metal/sinatra_test.rb

and access it with
http://localhost:9292/test


-Alex

Mittwoch, 24. Juni 2009

How do I tell Couch Potato to use http authentication?

During RailswayCon, I attended the session 'Ruby sittin on the Couch' by Alexander Lang in which he mentioned couch.io: Managed Hosting and Support for Apache CouchDB and also his GitHub project couch_potato. And last weekend I decided to try that all out.

After setting up the DB on couch.io, I managed to access it via CURL, but it took me a long time and a hint by Alexander Lang to figure out how to tell couch_potato to use BASIC AUTHENTICATION. Actually, you cannot use the default CouchPotato.database method. You have to create your own database instance with the underlying CouchRest:


# define the CouchDB server through CouchRest
CouchServer = CouchRest::Server.new "http://user:password@account.couch.io"

# create the CouchRest database
CouchRestDB = CouchRest::Database.new CouchServer, "database"

# use that with CouchPotato
CouchDB = CouchPotato::Database.new(CouchRestDB)


-Alex

P.S. this also ended up on the GitHub wiki page of couch_potato.