Twitter Updates

Showing posts with label Mac Ports. Show all posts
Showing posts with label Mac Ports. Show all posts

Tuesday, 15 December 2009

Sinatra First Blog attempt

After getting Xcode for Snow leopard correctly installed and restarting. The basic sinatra works correctly.

hi.rb
----
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end

Command line:
$ gem install sinatra
$ ruby hi.rb

Then checkout 127.0.0.1:4567.

Turning it an almost blog, with some erb and an sqlite 3 database.
Assuming you have macports installed you can do (or look up installing sqlite3):
$ sudo port install sqlite3
cd Sinatra_dir
sqlite3 blog
#you are now in the sqlite command prompt
sqlite> create table posts (title text, body text );
sqlite> insert into posts values('title1','Very long article');
sqlite> insert into posts values('Sinatra Blog Post','text text text text text');

hi.rb
----
require 'rubygems'
require 'sinatra'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:dbfile => 'blog.db'
)
class Post < ActiveRecord::Base
end

get '/news/?' do
@posts = Post.all()
erb :index
end


Now create ./views/index.erb
----
HelloWorld!

<% for post in @posts %>
< h 1><%= post.title %>< / h 1>
< p ><%= post.body%>< / p>
<% end %>


$ ruby hi.rb and goto 127.0.0.1:4567.
If all goes well you should see some thing like this:

Monday, 14 December 2009

Problems with Snow Leopard and Ruby Gems

UPDATE 2 (update 1 at the bottom with some extra ruby version info)
When you install Xcode make sure is is the latest version. I must have at some point installed the old Leopard version. then when things did not work reinstalled that same old version. I found xcode321_10m2003 in my downloads folder not the older one I had put in a software folder. You may still need to update Ruby to a new version.

Make sure you have the latest Xcode.


I have been trying to get the very simple Sinatra (a light ruby on Rails) setup working following the verysimple instructions on http://www.sinatrarb.com/

Make a file called hi.rb with this inside:
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end

Then run these commands:
$ gems install sinatra
$ ruby hi.rb


They fail with:
hi.rb:2:in `require': no such file to load -- rubygems (LoadError)
from hi.rb:2

After removing the require 'rubygems', is it actually still required ?
hi.rb:3:in `require': no such file to load -- sinatra (LoadError)
from hi.rb:3

To fix this I ran through the instructions at http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/

Their instructions worked well until the mysql gem which I do not require at the moment but do like to get my set up the same as the tutorial. I found the following line on stackoverflow.
$ sudo env ARCHFLAGS="-arch x86_64" gem install mysqlplus


Finally got the basic sinatra working by calling:
$ /usr/local/bin/ruby hi.rb
Even though which ruby returns /usr/local/bin/ruby, so why does ruby hi.rb not just work!

What is going on just thought I would check to see if calling the other ruby breaks it, but it works fine.
$ /usr/bin/ruby hi.rb


UPDATE
For completeness and to answer Spyro7's Question:
$ /usr/local/bin/ruby -v
> ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0]

$ /usr/bin/ruby -v
> ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]

Monday, 2 November 2009

mac ports since OS X Snow Leopard upgrade

Since upgrading to Snow Leopard I have noticed that Mac Ports (Previously called Darwin Ports) started giving me lots of errors. So I manually downloaded and installed the latest version, from here.

I then had to run through the insructions here [1] to clean every thing up:
[1] http://trac.macports.org/wiki/Migration

$ port installed > myports.txt
$ sudo port clean all
$ sudo port -f uninstall installed


The look through myports.txt and install any you need.

$ sudo port install fping scite