Ultimi aggiornamenti: ruby RSS

  • Rails – number format hack 

    bigonazzi 20:08 on 25 March 2009 Permalink | Replica
    Tag: github, I18n, ruby, , Software

    Ciao, il supporto all’internazionalizzazione (wow, spero di averlo scritto giusto!) di Rails ha fatto incredibili passi avanti nelle ultime versioni. Purtroppo al momento non tutto il framework utilizza il nuovo modulo I18n. In particolare i form helpers non lo usano. Ho dato un’occhiata in giro (google) e non sono riuscito a trovare una soluzione semplice (i dati vanno comunque salvati sul db), quindi ho deciso di scrivere una piccola libreria che risolva il problema temporaneamente. Per ogni campo vengono creati due attributi virtuali (eg: formatted_decimal :total => “formatted_total”, “formatted_total=” ) da usare nelle viste al posto dell’attributo vero e proprio. Serve solo definire il formato numerico per il “locale” corrente (eg: config/locale/it.yml).

    Scrivere un plugin per un semplice file mi pareva eccessivo. Eccovelo.

    dArio

     
  • Stand-alone ActiveRecord 

    bigonazzi 19:08 on 9 February 2009 Permalink | Replica
    Tag: ActiveRecord, , mysql, ruby

    Good thing the intertubes still are delivering vital hints even during this bleak times… I was trying to use ActiveRecord inside a small script of mine and I ran into some issues. I’m using OSX 10.5.6 “Leopard” and MacPorts.

    First I needed to install activerecord, easy:

    sudo gem install activerecord

    I used mac port to install mysql:

    sudo port install mysql5 +server

    now the triky part, installing the mysql gem. First download and modify the mysql gem:

    sudo gem install mysql

    this will fail. Now you need to navigate to the gem cache dir:

    cd /opt/local/lib/ruby/gems/1.8/cache

    then unpack the gem

    sudo gem unpack mysql-2.7.gem

    cd mysql-2.7

    with your favourite editor add this line to mysql.c.in

    #define ulong unsigned long

    now rebuild the gem and install it

    sudo gem build mysql.gemspec

    sudo mv mysql-2.7.gem ../mysql-2.7-CUSTOM.gem

    Almost there, we need to install our shiny-new gem:

    sudo env ARCHFLAGS=”-arch i386″ gem install mysql-2.7-CUSTOM.gem — \

    –with-mysql-config=/opt/local/bin/mysql_config5

    Ok, all is done (u might need to install some missing parts) now all you need to do is to add some requires to your script and remember to always establish a connection before using any ActiveRecord resources:

    require ‘rubygems’
    require ‘active_record’

    dbConfig = {“adapter” => “sqlite3″, “dbfile” =>  ‘./file.db’}

    ActiveRecord::Base.establish_connection(dbConfig)

    class Stuff < ActiveRecord::Base

    Hope somebody finds this usefull!

    dArio

    [thanks to kpumuk.info/ and http://www.kudelabs.com/2008/09/12/installing-mysql-gem-on-macos-x-leopard ]

     
  • Sproutcore + Rails 

    bigonazzi 14:06 on 22 July 2008 Permalink | Replica
    Tag: , , rails, ruby, srpoutcore, web

    Because of MobileMe and Live Mesh (the latter being Microsoft’s latest weapon to be a big boy on the internet, and I predict this time they will finally succeed big time), I found out that MobileMe is actually based on this open source javascript framework named Sproutcore.

    You have to look for yourself what it’s all about. This is not like Prototype, jQuery or all those others. This takes MVC to the web browser, advocating fat clients. It does this with Cocoa inspired features.

    Read the rest…

    dArio

     
c
scrivi un nuovo post
j
post successivo/commento successivo
k
post precedente/commento precedente
r
rispondi
e
modifica
o
mostra/nascondi commenti
t
torna a inizio pagina
l
go to login
h
show/hide help
esc
Annulla