Categoria: Ruby on rails

tutorials ruby on rails

Questo tutorial ci mostra come randomizzare gli elementi di un array con ruby on rails

# external...  
def shuffle(arr)  
  arr.sort {|a, b| rand <=> 0.5 }  
end 
 
# ...or as part of Array  
class Array 
  def shuffle  
    self.sort {|a, b| rand <=> 0.5 }  
  end 
end  

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Reddit
  • scuttle
  • Smarking
  • Spurl
  • YahooMyWeb
  • DZone
  • Internetmedia
  • Snap2r
  • Technorati

In questo tutorial vedremo come creare uno script in ruby per effettuare il backup di tutto o una parte di un database. Il risultato sarà un file con le istruzioni sql.

require 'dbi'  
tables = "tabella_per_backup1", "tabella_per_backup2" 
data = Array.new 
dbh = DBI.connect("DBI:Mysql:my_db", "user", "psswd" )  
tables.each{ |table|  
    # visualizza le tabelle  
    str = "SHOW CREATE table #{table};" 
    sth = dbh.prepare( str )  
    sth.execute  
    data.push sth.fetch[1].gsub( /`/, "" ) + ";" 
    # e il loro contenuto 
    str = "SELECT * FROM #{table};" 
    sth = dbh.prepare( str )  
    sth.execute  
    # fa un ciclo e crea codice sql
    while row=sth.fetch  
        insert = "INSERT INTO #{table} VALUES(" 
        first = true 
        row.each{ |val|  
            if val.nil?  
                insert << ", null" 
            else 
                val = "#{val}" 
                val.gsub!( /"/, "\\\"" )  
                first == true ? insert << "\"#{val}\"" : insert << ",\"#{val}\"" 
            end 
            first = nil 
        }  
        insert << ");" 
        data.push insert  
    end 
}  
dbh.disconnect 
# stampa il tutto
data.each_index{ |i|  
    puts data[i]  
}  

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Reddit
  • scuttle
  • Smarking
  • Spurl
  • YahooMyWeb
  • DZone
  • Internetmedia
  • Snap2r
  • Technorati
02
03

ruby on rails handbook

posted di Administrator, in Ruby on rails, tutorials. No Commenti

What is Ruby on Rails?


Screencasts & Videos

...

Tutti gli altri link su: http://railshandbook.com/

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Reddit
  • scuttle
  • Smarking
  • Spurl
  • YahooMyWeb
  • DZone
  • Internetmedia
  • Snap2r
  • Technorati
07
12

Progress Bars con GD2 e Ruby

posted di Administrator, in Ruby on rails, php, tutorials. No Commenti

In questo articolo vedremo come realizzare un preloader con Ruby on Rails e php come questo.

OSX-ish:
rpb-output1.png 

WinXp-ish:
rpb-output1.png 

Generic LED-ish:
rpb-output1.png

Solaris-ish:
rpb-output1.png

Puoi scaricare i files di esempio qui: ruby_progressbar.tar.gz.

Puoi leggere l'articolo completo : http://jordan.husney.com/archives/2005/12/progress_bars_w_1.php

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Reddit
  • scuttle
  • Smarking
  • Spurl
  • YahooMyWeb
  • DZone
  • Internetmedia
  • Snap2r
  • Technorati

Questo tutorial mostra come installare Ruby on Rails su Ubuntu Linux che è simile a Xubuntu, e distribuzioni Debian-based.
Cominceremo con una installazione base da linea di comando.

sudo apt-get install ruby ruby1.8-dev irb

ti mostrera di inserire una password in modo da essere sicuri
Installato Ruby ora installiamo SQLite un database basato su file ottimo per lo sviluppo. Se vuoi puoi usare anche un altro database come MySQL o PostgreSQL.

sudo apt-get install sqlite3

Adesso iniziamo a installare Rails. Come prima cosa hai bisogno di RubyGems. Scaricalo cosi:

wget http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz

Spacchetta il file compresso

tar -zxvf rubygems-0.8.11.tgz

Andiamo nella directory creata e avviamo il processo di setup

cd rubygems-0.8.11
sudo ruby setup.rb

Adesso che abbiamo installato rubygem installiamo ruby on rails

sudo gem install rails --include-dependencies

Installeremo cosi l'ultima versione di Rails (1.1.4 al momento).

Creiamo una applicazione di test cosi

rails my_test_app

Avviamo la nostra applicazione per vedere se funziona l'installazione:

cd my_test_app
ruby script/server

Andiamo su http://localhost:3000 nel nostro browser e verifichiamo.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Reddit
  • scuttle
  • Smarking
  • Spurl
  • YahooMyWeb
  • DZone
  • Internetmedia
  • Snap2r
  • Technorati

Installare ruby on rails su windows

L'installazione di ruby in windows è davvero semplice .Come prima cosa dobbiamo scaricare Ruby installer. Poi semplicemente avviare la procedura di installazione .Ci chiederà dove vorremo installare il programma e noi sceglieremo "c:" per comodità.

L'installer, installerà come editor un text editor chiamato SciTE (the Scintilla Text Editor). Tu puoi avviare SciTE selezionandolo dal menu di avvio.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Reddit
  • scuttle
  • Smarking
  • Spurl
  • YahooMyWeb
  • DZone
  • Internetmedia
  • Snap2r
  • Technorati
web tracker