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