rubyonrails - 白牙的日志 - 努力哇!

centOs+passenger+nginx+rails+mysql环境搭建

yum groupinstall "Development Tools"
yum install zlib-devel wget openssl-devel



wget http://rubyforge.org/frs/download.php/66162/ruby-enterprise-1.8.7-2009.10.tar.gz
tar xzvf ruby-enterprise*
./ruby-enterprise*/installer
 export PATH=$PATH:/opt/ruby/bin

wget http://www.nginx.eu/download/sources/nginx-0.8.9.tar.gz

wet http://rubyforge.org/frs/download.php/63009/passenger-2.2.5.tar.gz
tar xzvf passenger*.tar.gz
./opt/ruby/bin/passenger-install-nginx-module
1
2
/home/nginx-0.8.9
 --with-http_ssl_module



vim  /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx – this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /opt/nginx/conf/nginx.conf
# pidfile: /opt/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
configtest || return $?
stop
start
}

reload() {
configtest || return $?
echo -n $”Reloading $prog: ”
killproc $nginx -HUP
RETVAL=$?
echo
}

force_reload() {
restart
}

configtest() {
$nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
status $prog
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac

chmod +x /etc/rc.d/init.d/nginx
chkconfig --add nginx
chkconfig --level 35 nginx on




 yum install mysql mysql-server mysql-devel

gem install mysql --no-rdoc --no-ri -- --with-mysql-dir=/usr/bin \
    --with-mysql-lib=/usr/lib/mysql --with-mysql-include=/usr/include/mysql

chkconfig mysqld on ; /etc/init.d/mysqld start

wget http://kernel.org/pub/software/scm/git/git-1.6.5.2.tar.gz
tar zxvf git-1.6.5.2.tar.gz
./git*/configure
make
make install

配置Spree
mkdir /www
git clone git://github.com/railsdog/spree.git spree
http://github.com/railsdog/spree
useradd www-data
chown www-data /www/spree/public/javascripts
chown www-data /www/spree/public/stylesheets
chmod 0777 /www/spree/public/javascripts
 chmod 0777 /www/spree/public/stylesheets
 chmod u+g /www/spree/public/stylesheets
 chmod u+g /www/spree/public/javascripts
 

在VPS上的Cent OS 5.3 打造Rails服务器

编译前得准备

 yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel
 

编译安装

http://blog.dt.org/index.php/2008/11/installing-lighttpd-ruby-on-rails-fastcgi-and-mysql-on-rhel-5/

 

部署FTP

http://www.cyberciti.biz/faq/rhel-centos-linux-install-ftp-server/

 

ftp配置

http://www.javaeye.com/topic/340655

 

 

acts_as_nested_set得使用

安装:ruby script\plugin install acts_as_nested_set

Api

 

  • root?() – 是否是根对象
  • child?() – 是否是子对象(拥有父对象)
  • unknown?() – 不知道该对象的状态(既不是根对象,也不是子对象)
  • add_child(child_object) – 为根对象添加一个子对象(如果child_object是一个根对象的话,则添加失败)
  • children_count() – 根对象的所有子对象的个数
  • full_set() – 重新找到所有对象
  • all_children() – 根对象的所有子对象
  • direct_children() –根对象的直接子对象

example

 

        http://ruby.codefetch.com/example/jo/rails-code/ar/acts_as_nested_set.rb?qy=web

        

rails学习笔记一

建立一个rails project,名字叫"test",数据库采用mysql

rails  test -d mysql

mysql设置了密码,必须设置下数据库的访问密码

vim config/database.yml 

运行rake db:create 创建development环境的数据库

创建model

script/generate model XXX

增加一列

script/generate  migration add_columnname_to_XXX  columnname :type

增加测试数据

script/generate migration add_test_data

vim db/migrate/20091019012237_add_test_data.rb
 

def self.up
  3     Product.delete_all
  4     Product.create(:title => "PVC",
  5                    :description => %Q{
  6                    <p>
  7                    This is book
  8                    </p>
  9                    },
 10                    :price => 11,
 11                    :image_url => 'imgaes/svn.jpg')
 12   end
 13
 14   def self.down
 15     Product.delete_all
 16   end
 

添加后台管理页

script/generate model test

script/generate controller admin/test

vim congi/routes.rb

map.namespace :admin do |admin|

    admin.resources :tests

end

 

Restful Authentication with rails 2

http://avnetlabs.com/rails/restful-authentication-with-rails-2

http://avnetlabs.com/rails/restful-authentication-with-rails-2-usage




Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee