2009年8月22日土曜日

Rails on heroku

heroku.com上でRailsAppをdeployしたときのメモ

環境:
MacOSX 10.5.8
ruby 1.8.7 (2008-08-11 patchlevel 72)
rails 2.3.3
heroku-gem/1.1

手順:
localでdevelop

$ rails heroku
$ cd heroku
$ ./script/generate i18n_scaffold status content:text
$ rake db:migrate

*localでdbのmigrateして、deploy時に必要に応じてdb:pushする

$ ./script/generate i18n ja
$ cat config/environment.rb
config.time_zone = 'Tokyo'
config.i18n.default_locale = 'ja'

*i18n化 http://rails-i18n.org/wiki/wikipages/i18n-rails-guide


$ ./script/plugin install git://github.com/technoweenie/restful-authentication.git
$ mv vendor/plugins/restful-authentication/ vendor/plugins/restful_authentication/

>IMPORTANT FOR RAILS > 2.1 USERS To avoid a NameError exception (lighthouse tracker ticket), check out the code to have an underscore and not dash in its name:
*restful_authenticationはrenameが必要(?)のため、vendor/pluginsにinstall。他のはheroku上でinstallする。

$ ./script/generate authenticated user sessions
$ cat app/controllers/application_controller.rb
include AuthenticatedSystem
$ rake db:migrate

*restful_authenticationのためのmigrate

$ vi config.environment.rb
config.gem "searchlogic"
config.gem "will_paginate"
config.gem "jpmobile"

*localでは他のpluginはsudo gem installでインストールしておく


$ cat .gems
searchlogic
will_paginate
jpmobile

*.gemsにheroku上でのmanifestを書いておく。
herokuのplatform上に既にインストールされているgemsはhttp://installed-gems.heroku.com/

で、いろいろ開発して、git&heroku


$ heroku create appname
$ heroku info --app appname

*gitアカウント作成、キー登録後に、appの作成

$ git init
$ git add .
$ git commit -m "my first commit"


$ git remote add heroku git@heroku.com:appname.git
$ git push heroku master

*git remoteリポジトリにherokuを登録し、masterブランチにpush


$ heroku db:push

*必要に応じて、delopmentDBをdeployのherokuにpush。もしくはheroku rake db:migrateか?

$ heroku restart

*app serverのリスタート

2009年7月24日金曜日

gem 1.3.5 さくら

%cat .cshrc
set path $HOME/ROOT/bin
setenv RUBYLIB $HOME/ROOT/lib
setenv GEM_HOME $HOME/ROOT/lib/ruby/gem

%mkdir $HOME/ROOT
%ruby setup.rb --prefix=$HOME/ROOT

%gem18 -v
1.3.5

%gem18 update --system
Updating RubyGems
Nothing to update

%setenv RB_USER_INSTALL true
%gem18 install hpricot

2009年7月4日土曜日

MacOS Leopard メニューを隠す

1. Appを右クリック、パッケージの中身を表示を選択
2. ContentsフォルダーのInfo.plistを開く
3. Information Property Listにアイテムを追加
4. 新しいKeyに「Application UI Presentation Mode」を追加して、Valueを「4」(All Suppressed)に
5. 編集したInfo.plistを保存

2009年5月27日水曜日

Ruby AWS API

amazon-ecs http://amazon-ecs.rubyforge.org/doc/
ruby-amazon http://raa.ruby-lang.org/project/ruby-amazon/
ruby-aws (ruby-aaws) http://www.caliban.org/ruby/ruby-aws/
ruby-aws http://rubyforge.org/projects/ruby-aws

2009年5月15日金曜日

searchlogic と asct_as_taggable_on

ActiveRecordへのhookのタイミングか、searchlogicでtagが指定できない。
とりあえず、
  • find_tag_with でtagによる絞り込みをオブジェクトへ
  • 絞り込んだオブジェクトに対して、searchlogic
でOK。ソースは読んでいない

2009年4月26日日曜日

friendly_id

http://github.com/norman/friendly_id/
slug対応。
table_name_prefixを使っていると、
rake friendly_id:make_slugs MODEL=MyModelName
でエラー。

とりあえず、friendly_id/lib/tasks/friendly_id.rakeの
while records = sluggable_class.find(:all, :include => :slugs, :conditions => "table_prefix_slugs.id IS NULL", :limit => 1000) do
で無理くり通す。

2009年4月22日水曜日

MySQL column auto incrementのリセット

mysql> delete from ff_musics;
Query OK, 1 row affected (0.00 sec)
mysql> alter table ff_musics AUTO_INCREMENT =1;

2009年4月21日火曜日

ActiveRecord foreign_key

モデルが同じオブジェクトへのリレーションを設定する場合、

class User < ActiveRecord::Base
belongs_to :location, :foreign_key => :birth_place
belongs_to :location
end

以下のコードではViewでuser.locationがアクセスできない・・・

class User < ActiveRecord::Base
belongs_to :location
belongs_to :location, :foreign_key => :birth_place
end

2009年4月19日日曜日

safe_erb & safe_record

safe_erb & safe_record
./script/plugin install http://safe-erb.rubyforge.org/svn/plugins/safe_erb/
./script/plugin install git://github.com/authorNari/safe_record.git

2009年4月18日土曜日

paperclip thumb

paperclipプラグインでthumbを使うには、ImageMagick要。

sudo port install ImageMagick
でOK

2009年4月14日火曜日

generate migrate

./script/generate migration add_column_to_tables column:integer
とすると、Tablesテーブルにcolumnカラム(integer)が追加されるmigrationファイルが自動的に生成される。

css Rails

app/views/layouts/application.rhtml などに
<%= stylesheet_link_tag "base.css" %>
を記述。base.css はpublic/stylesheets へ

scaffold で生成されたViewは
app/views/layouts にある html.erbを編集

2009年4月13日月曜日

restful_authentication

template
generate(:authenticated,"user sessions --include-activation --rspec")

environment.rb
config.active_record.observers = :user_observe

routes.rb
map.activate '/activate/:activation_code', :controller => 'users', :action => 'activate', :activation_code => nil


tutorial

2009年4月10日金曜日

Rails table prefix

DB数が限られているホスティングで必須なテーブル・プレフィックス。

config/environment.rb に
config.active_record.table_name_prefix = 'prefix_'

でOK。ActiveRecord,Scaffold,I18n_scaffoldもdb:create,db:migrateでprefix付きのテーブルがcreateされる。

2009年4月6日月曜日

vim-ruby on MacOSX

MacOSXにvim-rubyをインストール。

MacOSX 10.5.6
MacPort 1.710
sudo port -d selfupdate
sudo port -d sync

vim 7.2.147
port variants vim
sudo port install vim +ruby

vim-ruby vim-ruby-2007.05.07
sudo gem install vim-ruby
vim-ruby-install.rb

.vimrc
set nocompatible
syntax on
filetype on
filetype indent on
filetype plugin on
compiler ruby
set expandtab
set tabstop=2 shiftwidth=2 softtabstop=2
set autoindent

2009年3月5日木曜日

gem install mysql on MacOS Leopard

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

mysqlはmacportではなく、mysqlのMacOSXをインストール済み。

2009年2月27日金曜日

uninstall zumoDrive on MacOSX

http://www.zumodrive.com/forums/12/topics/27

# First, go to System Preferences, then the Accounts page, then click on the Login Items tab. Find ZumoDrive in the list and uncheck it.
# Uninstall MacFUSE using the preference pane, remove the preference pane afterwards
# Remove ZumoDrive the application from /Applications
# Remove the directory: ~/Library/Application Support/ZumoDrive
# Remove the preferences file: ~/Library/Preferences/com.zecter.configuration.plist
We also install growl on the machine if you didn’t have it before. You can uninstall that with the growl uninstaller available

2009年2月17日火曜日

Security Update 2009-001

http://support.apple.com/kb/HT3438?viewlocale=ja_JP

2009年2月16日月曜日

Impressive-0.10.2 on MacOS Leopard

ImpressiveをLeopardへインストール。

Python 2.5.1
Impressive-0.10.2
- PyOpenGL http://pyopengl.sourceforge.net/
- PyGame http://www.pygame.org/
-- SDL framework for making PyGame
--- http://pygame.org/wiki/MacCompile
- PIL http://www.pythonware.com/products/pil/
Xpdf(MacPort)
GhostScript(MacPort)
pdftk(MacPort)
MPlayer(MacPort)