пятница, 31 июля 2009 г.

Gentoo + rails + passenger + nginx


I installed ruby by compiling it myself (portage handled ruby doesn't quite do
it for me...). Then I installed the passenger gem 2.2.4. After installing
passenger gem went to the root passenger dir and ran "rake nginx" to get the
helperserver needed. Then I copied the nginx-0.7.61.ebuild and modified it to
include the use flag passenger. Then using the hint from the ebuild attached to
this bug got the full path for the nginx passenger module and put that into my
ebuild.

Then added the passenger use flag to /etc/portage/package.use for nginx and
emerged nginx 0.7.61 with passenger.

Added the config info to /etc/nginx.conf and I'm away everything works very
nicely :)


via http://bugs.gentoo.org/266446

вторник, 28 июля 2009 г.

Любителям длинных имён переменных

%username%, помни:
url -- полный путь к странице: http://localhost/blog/2009/07/28/kak-ya-upal-v-rechku
path -- только путь: blog/2009/07/28/kak-ya-upal-v-rechku

И не надо никаких названий переменных, типа: full_path, relative_path, etc.

среда, 22 июля 2009 г.

Converting Drupal tables to RoR from any to any database.

OK, OK, it's fairly not only for Drupal source databases :-)

STEP 1 - init databases connections
Create two new connections in database.yml file like this:


# DATABASE CONVERTING SPECIFIC
# old connection
old:
adapter: mysql
database: dbname
username: username
password: userpass
host: localhost

# new connection (may be like your development or production connection)
new:
adapter: postgresql
database: dbname
username: username
password: userpass
schema_order: development # for example
host: localhost


STEP 2 - write rake task
create convert.rake file in your lib/tasks rails application directory

1 namespace :db do
2 namespace :convert do
3 task :old2new => :environment do
4 print "OK, let's do it now!\n"; STDOUT.flush
5
6 # define universal model for old tables
7 class OldModel < ActiveRecord::Base
8 end
9
10 # demonic convertor
11 def convert(srctable, dstclass)
12 print "- converting class " + dstclass.to_s + "...\n"; STDOUT.flush
13
14 dstclass.establish_connection(:new)
15 dstclass.delete_all
16
17 OldModel.set_table_name(srctable)
18 OldModel.find(:all).each { |old|
19 new = dstclass.new
20 new = yield(old, new)
21 new.save(false)
22 }
23 end
24
25 # connect to old dying database
26 ActiveRecord::Base.establish_connection(:old)
27
28 # CONVERTING
29
30 # users
31 convert('rctc_users', User) {|old, new|
32 # prepare each field individually, yeah.
33 new.id = old.uid
34 new.login = old.name
35 new.email = old.mail
36 new.password = Digest::MD5.hexdigest(old.pass + SALT)
37 new
38 }
39
40 # convert your tables below like above
41 # ...
42
43 print "Wow! Processing complete!\n"
44 end
45 end
46 end

STEP 3 - RUN IT!

$ rake db:convert:old2new

суббота, 18 июля 2009 г.