before rvm install 1.9.2
, make sure
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion nodejs
rvm requirements
可以列出依赖的软件。
跑passenger-install-apache2-module
时出来的提示sudo apt-get install libopenssl-ruby
是坑爹的,跟本没有。
解决方法:
rvm remove 1.9.2
rvm pkg install openssl
rvm install 1.9.2 --with-openssl-dir=$HOME/.rvm/usr
bundle install RAILS_ENV=production
是个错误的命令,因为bundle会把后面的都当成安装gem的目标路径。它会产生一个名为./RAILS_ENV的文件夹,并拿它作为以后不bundle安装的默认路径。
如果不慎打错了,解决方法: rm .bundle -rf
cd `bundle show rails`
可以cd到某gem所在的目录。
rails s -e production;
rails c production;
rake xxx:run RAILS_ENV=production;
对于那种『有可能错误但错了也不碍事』的命令,可以在后面加一个; true
,比如
run "kill -QUIT `cat #{deploy_to}/shared/pids/unicorn.pid`; true"
有时在application.rb下加上这一行:
APP_CONFIG = YAML.load_file("#{Rails.root}/config/app_config.yml")
在production模式下是有坑的。YAML.load_file
的结果是一个字符串为key的哈希,如果用symbol取东西就会出错(但在development模式下一切正常)。解决方法是换成ActiveSupport中的HashWithIndifferentAccess
:
APP_CONFIG = HashWithIndifferentAccess.new YAML.load_file("#{Rails.root}/config/app_config.yml")
add_column
时如果不小心把boolean
敲成bool
,会把sqlite的的db:schema:dump
搞坏掉,而sqlite并不允许更改column的名字。只能用一种蛋疼的work around。
在database.yml
中没有设置collation: utf8_general_ci
的话跑出来的schema似乎会选用数据库的默认collate? 如下脚本可以更改数据库中所有表的collation为utf8_general_ci
:
mysql --database=dbname -B -N -e "SHOW TABLES" \
| awk '{print "ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"}' \
| mysql --database=dbname &
ubuntu源里的mongodb-server
是坑爹的,版本太低,正确的是mongodb-10gen
,需要加个源。
一段小脚本,无关rails,但可以提升跑rake task时的来福值。
迥,www.railstutorial.org 这本书写的巨好,按照书中所介绍的安装步骤,完全顺利地安装~