Monday, October 20, 2008

ruby, gem, rails, debian lenny, sqlite3, mysql, Days on Rails.



Source
http://www.rubyonrails.org/docs
http://rails.homelinux.org
http://www.rails4days.pwp.blueyonder.co.uk/Rails4Days.pdf
http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html



( apt-get install rails )


( $rails ToDo )


( Debug in different terminals:
$tail -f ToDo/log/server.log
$tail -f ToDo/log/development.log )


( Edit /etc/apache2/httpd.conf


ServerName todo
DocumentRoot /home/maximilianou/src/ToDo/public

Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny

)


( Edit /home/maximilianou/src/ToDo/public/.htaccess

RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] )



( #a2enmod rewrite )


( /etc/init.d/apache2 restart )


( View in iceweasel http://localhost:3000/ Ok.
View in iceweasel http://localhost:3000/rails/info/properties Ok.
View in iceweasel http://todo Ok. )


( Not Found .. http://todo/rails/info/properties )


( #apt-get install libapache2-mod-fcgid libfcgi-ruby1.8

#a2enmod ssl
#a2enmod suexec
#a2enmod include
#/etc/init.d/apache2 restart )


( Not Found .. http://todo/rails/info/properties )


now reading..


Ok!!, Thanks to Oficial Communities like rubyonrails.org, www.debian-administration.org

This is going to be better
http://wiki.rubyonrails.org/rails/pages/RailsOnDebian
( It's up to date [Updated on October 09, 2008 21:55 by Ben Carpenter] )
And
http://www.debian-administration.org/articles/329

I have a new installation of my debian now.
You have to make previous steps remove the software installed.


#aptitude update
#aptitude upgrade



#aptitude install rubygems
#aptitude install build-essential

Now gem is running from everywhere, # or $.


( RubyInstaller http://rubyinstaller.rubyforge.org, but not now. )

gem install rails --include-dependencies ( so similar to debian apt-get, perfect!! )



( Just to see: MySql Ruby Driver http://www.tmtm.org/en/mysql/ruby/, but it is in gem )
( Just to see something else: Ruby::DBI http://ruby-dbi.rubyforge.org/
http://ruby-dbi.rubyforge.org/rdoc/index.html
#gem install dbi
#gem install dbd-mysql )


Keeping Rails Up-To-Date
#gem update rails



now installing mysql in lenny.
http://maximilianou.blogspot.com/2008/10/debian-lenny-amd64-mysql.html


#aptitude install libmysql-ruby
#aptitude install ruby

This have to return true:
#ruby -e 'puts require "mysql"'

This have to return error:
#ruby -e 'puts require "postgres"'


$mkdir src
$cd src
$mkdir work
$cd work
$rails demo
bash: rails: command not found


$gem list

*** LOCAL GEMS ***

actionmailer (2.1.2)
actionpack (2.1.2)
activerecord (2.1.2)
activeresource (2.1.2)
activesupport (2.1.2)
rails (2.1.2)
rake (0.8.3)


$ls /var/lib/gems/1.8/bin
rails rake

#vi /etc/bash.bashrc
export PATH=$PATH:/var/lib/gems/1.8/bin

$exit

Open a new terminal

$rails -v
Rails 2.1.2


$cd src/work
$rails demo


( Just to see something else
to use mongrel:
gem install mongrel
http://mongrel.rubyforge.org,

but the faster is lighttpd:
http://www.lighttpd.net )


$cd demo
$vi README
...
== Apache .htaccess example
...


Well, in two different terminals run:

$cd src/demo
$tail -f log/development.log

$cd src/demo
$tail -f log/server.log

More log and debug info in README
( script/dbconsole
script/dbconsole production
)


$ruby script/server
=> Booting WEBrick...
/var/lib/gems/1.8/gems/rails-2.1.2/lib/initializer.rb:229:in `require_frameworks': no such file to load -- openssl (RuntimeError)

I don't want to recompile anything, like some blogs wrote. I want default things, the simplest way, for continuous upgrading.

so..
from http://www.nabble.com/Webrick-%27require_frameworks%27-message-td14527746.html
message from Carl Anderson

#gem update rails -y
#apt-get install libopenssl-ruby

..and, everything is fine again.

http://localhost:3000/ OK!!


$./script/generate controller Say

$vi app/controller/say_controller.rb
..
def hello
end
..

Where the server is running [Ctrl-c]
$./script/server

http://localhost:3000/say/hello

MissingSourceFile in SayController#hello

no such file to load -- sqlite3

( from http://weblog.rubyonrails.org/2007/12/17/rails-2-0-2-some-new-defaults-and-a-few-fixes
$rails -d mysql myapp
to use mysql in the new app )

( from http://www.ruby-forum.com/topic/136133
$gem install sqlite3-ruby
Where the server is running [Ctrl-c]
$./script/server
Not a solution )

from http://www.nabble.com/%22no-such-file-to-load----sqlite3%22-Rails-td15808271.html
$apt-get install sqlite3
Where the server is running [Ctrl-c]
$./script/server
Not a solution

from http://www.nabble.com/%22no-such-file-to-load----sqlite3%22-Rails-td15808271.html
Message from Shandy Nantz-2

$apt-get install libsqlite3-ruby
Where the server is running [Ctrl-c]
$./script/server

http://localhost:3000/say/hello
Template is missing, Ok!!!!


$vi app/views/say/hello.rhtml
< html >< body >< h1 >Hello from Rails< /h1 >< /body >< /html >

http://localhost:3000/say/hello

$vi app/controller/say_controller.rb
...
def goodbye
end
...


$vi app/views/say/hello.rhtml

Say < %= link_to "GoodBye", :action => "goodbye" % >



Short Iterations, and system's evolution .

It's easier to throw something away if you didn't spend a long time creating it.


$cd src/work
$rails -d mysql depot
$cd depot
$mysql -u root -p
mysql>create database depot_development
mysql>create database depot_test
mysql>create database depot_production
mysql>grant all on depot_development.* to 'dave'@'localhost';
mysql>grant all on depot_test.* to 'dave'@'localhost';
mysql>grant all on depot_production.* to 'dave'@'localhost' identified by 'wibble';
mysql>exit;
$vi db/create.sql

drop table if exists products;
create table products (
id int not null auto_increment,
title varchar(100) not null,
description text not null,
image_url varchar(200) not null,
price decimal(10,2) not null,
primary key (id)
);

$mysql -u dave -p depot_development < db/create.sql
password:wibble

$vi config/database.yml
username: dave
password: wibble

$ruby script/generate scaffold Product Admin
...
wrong number of arguments (1 for 2)




now Jumping!! where to go?
Problem with the instructions and de version of rails.
I'm not going to work with older versions.
So let's read Web Development.. fast and search other solutions after that.


( from: http://www.b-simple.de/documents
REST, RESTfull

>curl -H "Accept: application/xml" -i -X GET http://localhost:3000/projects/1
>curl -X DELETE http://localhost:3000/projects/1
http://localhost:3000/projects/1.xml
link_to "New", new_project_path
link_to "Edit", edit_project_path(project)

<% form_for :project, @project, :url => { :action => "create" } do |f| %>
...
<% end %>

New Form
form_for(:project, :url => projects_path) do |f| ...

Edit Form
form_for(:project, :url => projects_path(@project),
:html => { :method => :put }) do |f| ...

Destroy
link_to "Show", project_path(project)
link_to "Destroy", project_path(project), :method => :delete

project_url(1)
project_url


No REST:
redirect_to :controller => "project", :action => "show", :id => @project.id

REST:
redirect_to project_url(@project)

REST Routing
map.resources :projects
=>
projects projects_url, projects_path
project project_url(id), project_path(id)
new_project new_project_url, new_project_path
edit_project edit_project_url(id), edit_project_path(id)

map.resources :sprints,
:controller => "ontrack",
:path_prefix => "/ontrack/:project_id",
:name_prefix => "ontrack_"


REST Rails try to reflect the belong to of URLs, replace:

config/routes.rb
map.resources :iterations
with
map.resources :projects do |projects|
projects.resources :iterations
end

link_to "Iterations", iterations_path(project)

<%= button_to "Close", close_project_path(project) %>

Ajax
link_to_remote "Destroy", :url => project_path(project), :method => :delete

<%= javascript_include_tag :defaults %>
in the project.rhtml of the ProjectController

ontrack/app/views/projects/destroy.rjs
page.remove "project_#{@project.id}"

)



$rails -d mysql depot4
$mysql -u root -p
password:*****
mysql>create database depot4_development;
mysql>use depot4_development;
mysql>grant all privileges on depot4_development.* to 'mvcuser'@'localhost' identifiec by 'mvcuser';
mysql>quit
$vi db/create.sql
drop table if exists products;
create table products (
id int not null auto_increment,
title varchar(100) not null,
description text not null,
image_url varchar(200) not null,
price decimal(10,2) not null,
primary key (id)
);
$mysql -u mvcuser -p depot4_development < db/create.sql
password: mvcuser
$vi config/database.yml
username: mvcuser
password: mvcuser

$script/generate scaffold Product id:int title:string description:text image_url:string price:decimal
or
$script/generate scaffold Product title:string description:text image_url:string price:decimal

$script/server
http://localhost:3000/products
http://localhost:3000/products/new
http://localhost:3000/products/1
http://localhost:3000/products/1/edit



$vi db/create.sql
...
date_available datetime not null,
...
$mysql -u mvcuser -p depot5_development < db/create.sql
password:mvcuser
$script/generate scaffold Product
The name 'ProductsHelper' is either already used in your application


from http://www.ruby-forum.com/topic/156303
Let's generate de forms, from de table product, in the database, in one command.

#gem install scaffold_form_generator
$rails -d mysql depot7
$mysql -u root -p
mysql>create database depot7_development;
mysql>grant all privileges on depot7_development.* to 'mvcuser'@'localhost';
mysql>quit
$mysql -u mvcuser -p depot7_development < db/create.sql
$script/generate scaffold Product
$script/generate scaffold_form Product products
The name 'ProductsHelper' is either already used in your application


$rails -d mysql depot9
$cd depot9
$mysql -u root -p
password:*****
mysql>create database depot9_development;
mysql>grant all privileges on depot9_development to 'mvcuser'@'localhost';
mysql>quit
$cp ../depot7/db/create.sql db
$mysql -u mvcuser -p depot9_development < db/create.sql
password: mvcuser
$vi config/database.yml
username: mvcuser
password: mvcuser
$script/generate scaffold_form Product products
$script/server
http://localhost:3000/products
No route matches "/products" with {:method=>:get}


(plugin gettext_localize)
(plugin will_paginate)


Reading References from:
Luis Guardiola (Gasper) [http://www.wbs.com.ar/]
Martin Aceto [http://www.backing-online.com.ar/]

DONE: Read. Git Magic

DONE: Read. Agile Web Development - Chapter 15 and go on.
DONE: Read. Agile Web Development - Chapter 16 and go on.
DONE: Read. Agile Web Development - Chapter 17 and go on.
DONE: Read. Agile Web Development - Chapter 18 and go on.
DONE: Read. Agile Web Development - Chapter 19 and go on.
DONE: Read. Agile Web Development - Chapter 20 and go on.
DONE: Read. Agile Web Development - Chapter 21 and go on.
DONE: Read. Agile Web Development - Chapter 22 and go on.
DONE: Read. Agile Web Development - Chapter 23 and go on.

DONE: Read. The Rails Way - Chapter 1 - Bootstraping
DONE: Read. The Rails Way - Chapter 2
DONE: Read. The Rails Way - Chapter 3
DONE: Read. The Rails Way - Chapter 4
DONE: Read. The Rails Way - Chapter 5
DONE: Read. The Rails Way - Chapter 6
DONE: Read. The Rails Way - Chapter 7
DONE: Read. The Rails Way - Chapter 8
DONE: Read. The Rails Way - Chapter 9
DONE: Read. The Rails Way - Chapter 10
DONE: Read. The Rails Way - Chapter 11
DONE: Read. The Rails Way - Chapter 12
DONE: Read. The Rails Way - Chapter 13
DONE: Read. The Rails Way - Chapter 14
DONE: Read. The Rails Way - Chapter 15
DONE: Read. The Rails Way - Chapter 16
DONE: Read. The Rails Way - Chapter 17
DONE: Read. The Rails Way - Chapter 18
DONE: Read. The Rails Way - Chapter 19



Firefox Plugins
.Firebug
.Web Developer Tools




.irbrc

# load libraries
require 'rubygems'
require 'logger'
require 'wirble'

if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
end

# start wirble (with color)
Wirble.init
Wirble.colorize




script/generate migration AddColumnDisabledToRationType disabled:boolean

class AddColumnDisabledToRationType < ActiveRecord::Migration
def self.up
add_column :ration_types, :disabled, :boolean
end

def self.down
remove_column :ration_types, :disabled
end
end



TODO: Read. Design.Patterns.In.Ruby

TODO: Video: PeepCode 001 rjs

TODO: Video: Railscasts 1



(
bigdecimal, comma separator, decimal point, sqlserver adapter

C:\Ruby\lib\ruby\gems\1.8\gems\activerecord-2.1.2\lib\active_record\connection_adapters\abstract

../connection_adapter/../schema_definition.rb

# convert something to a BigDecimal
def value_to_decimal(value)
# Using .class is faster than .is_a? and
# subclasses of BigDecimal will be handled
# in the else clause
#print "value_to_decimal" + value +"\n"
if value.class == BigDecimal
#print "value_to_decimal value \n"
value
elsif value.respond_to?(:to_d)
#print "value_to_decimal value.to_d\n"
value = value.sub(/,/, '.')
#TODO:: value = value.sub(/,/, '.')
value.to_d
else
# print "value_to_decimal value.to_s.to_d\n"
value.to_s.to_d
end
end
)

debian, lenny, Desktop, kde, first day.



After an installation of a default base system:

Edit

/etc/apt/sources.list
deb http://debian.torredehanoi.org/debian lenny main contrib non-free



apt-get install kde

Friday, October 17, 2008

Insert a Data the .net way.. (today). Just work.




Inserting Data, the .net way... .
// firebird, id_ruta pk autoinc(generator and trigger before insert), ruta_nombre varchar
// Insert ruta.
RUTASDataSet.RUTASRow ruta = _rutasDataSet.RUTAS.NewRUTASRow();
ruta.RUTA_NOMBRE = nombre;

// Add ruta to DataSource.
_rutasDataSet.RUTAS.AddRUTASRow(ruta);

// Commit ruta to Database Table.
_rutasTableAdapter.Update(ruta);

// Update Visual DataGridView
Set RUTASDataSet.xsd > ID_RUTA "Delete Primary Key" !!
Set RUTASDataSet.xsd > ID_RUTA "AUTOINCREMENT" !!

( This is not the best solution, there could be inconcistances Database.ID_RUTA vs. Datagridview.ID_RUTA )




( Other solution is to use a Fill() in some place, after de commit )


Tuesday, October 14, 2008

java, web, netbeans, lenny




/etc/apt/sources.list
deb http://debian.torredehanoi.org/debian lenny main contrib non-free




#aptitude install netbeans




Download Netbeans 6.5 and execute from:
http://download.netbeans.org/netbeans/6.5/beta/bundles/netbeans-6.5beta-linux.sh

$netbeans-6.5beta-linux.sh


lenny, iceweasel = firefox, flash, i386 (amd64:no;)




/etc/apt/sources.list
deb http://debian.torredehanoi.org/debian lenny main contrib non-free




aptitude install iceweasel




/etc/apt/sources.list
...
deb http://www.backports.org/debian etch-backports main contrib non-free




#aptitude -t etch-backports install flushplugin-nonfree


Monday, October 13, 2008

debian, lenny, ethernet card rtl8139D = sc92031, kernel 2.6.24



Edit /etc/rc.local:

ifconfig eth0 192.168.1.110 broadcast 192.168.1.255 netmask 255.255.255.0
route add default gw 192.168.1.1
exit 0



Edit/Create /etc/resolv.conf

search cpe.telecentro.com.ar
nameserver 200.63.155.59
nameserver 200.63.155.187



#ping www.google.com.ar



http://www.debian.org/mirror/mirrors_full

Argentina:Edit /etc/apt/sources.list

deb http://debian.torredehanoi.org/debian lenny main contrib non-free
deb http://ftp.ccc.uba.ar/pub/linux/debian/debian lenny main contrib non-free



#apt-get update




Packages list:

http://packages.debian.org/testing/
http://packages.debian.org/testing/allpackages


Monday, October 6, 2008

Debian etch amd64 flash iceweasel

Debian etch amd64 flash iceweasel

Agregar en /etc/apt/source.list

deb http://www.backports.org/debian etch-backports main contrib non-free

luego ejecutar

#apt-get update

#apt-get -t etch-backports install flashplugin-nonfree

y listo.
Probar si funcionan los videos de youtube.