2009-05-31

[MAC]AppCleanerのインストール

AppCleanerとは、
MACのソフトをアンインストールするときに、関連ファイルを
同時に削除してくれるソフト。


(1)下記URLよりAppCleanerを取得する。

http://www.freemacsoft.net/


(2)インストール
  ①ダブルクリックでインストール開始
  ②aplicationフォルダに保存。

2009-05-26

rails2.0でscaffoldを実行する。


$ ruby script/generate scaffold person name:string age:integer


<参考/引用>
[技術][Ruby][Ruby on Rails]Rails 2.0のscaffoldを使ってみた

macOS X10.5.7にruby1.8.7+rails2.3.2をインストールする!

[目的]
・macOSX 10.5.7にruby1.8.7+rails2.3.2の開発環境を構築する。
 (デフォルトruby 1.8.6なのでruby1.8.7をソースからインストールする。)

[環境]
Rails 2.3.2
Ruby 1.8.7
macOSX 10.5.7

[作業方法]
(1)XcodeTools他のインストール。
 (付属のMac OS X Install Disc2 からインストール)
 ※インストール画面にて、WebObjectsをチェックし、
  追加でインストールする。

(2)環境変数の設定

%export PATH=/usr/local/bin:/opt/local/bin:/opt/local/sbin/:$PATH
%export MANPATH=/opt/local/man:/opt/local/share/man:$MANPATH

(3)Ruby1.8.7のインストール
 1.8.7をソースからコンパイルして/usr/localにインストールする
http://www.ruby-lang.org/ja/downloads/

% curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
% tar zxvf ruby-1.8.7-p72.tar.gz
% cd ruby-1.8.7-p72
% ./configure --prefix=/usr/local --enable-shared --enable-pthread
% make
% sudo make install
% make clean


% ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.4.0]
% which ruby
/usr/local/bin/ruby

(4)gemのインストール

http://rubyforge.org/frs/?group_id=126

% ftp http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
% tar zxvf rubygems-1.3.1.tgz
% cd rubygems-1.3.1
% sudo ruby setup.rb


% gem -v
1.3.1
% which gem
/usr/local/bin/gem

(4)rails 2.3.2をインストール


% sudo gem install rails

% rails -v
Rails 2.3.2
% which rails
/usr/local/bin/rails

(5)sqlite3をインストール

SQLiteのインストール
% port install sqlite3

sqlite3-rubyのインストール
% gem install sqlite3-ruby


(6)bash_profileの設定
※再起動後、rubyパスが1.8.6に
 戻っていたため、上記設定を実行。

% echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile


<参考/引用>
Mac OS X 10.5.6(Leopard) にRuby on Rails インストール
Mac OS X (10.4/Tiger)でSQLiteを使う際の注意点
Ruby Install Guide::MacOS X

2009-02-12

RailsのAPIドキュメント

[目的]
railsのAPIドキュメントをローカルから見たい。

[環境]
Rails 2.2.2
ActionMailer 2.2.2
Ruby 1.8.7

[方法]
(1)ドキュメントの生成

rake rails:freeze:gems
rake doc:rails


(2)確認
doc/api/index.htmlをブラウザーで開く。

[参考]
RailsのAPIドキュメントいろいろ

2009-02-11

RailsのActionMailerによるメール送信

[目的]
Gmailのsmtpを利用して、メールを送信する。

[環境]
Rails 2.2.2
ActionMailer 2.2.2
Ruby 1.8.7
ubuntu 8.04

[作業方法]
(1)TLSライブラリのインストール(gmailのsmtp認証用)
 ◆フォルダ
vendor/plugins/action_mailer_tls
vendor/plugins/action_mailer_tls/lib

◆ファイル
  vendor/plugins/action_mailer_tls/init.rb

  init.rbの中身

require_dependency 'smtp_tls'


  vendor/plugins/action_mailer_tls/lib/smtp_tls.rb

smtp_tls.rbの中身

require "openssl"
require "net/smtp"

Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args user, secret if user or secret

sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
@socket = Net::InternetMessageIO.new(sock)
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output

check_response(critical { recv_response() })
do_helo(helodomain)

raise 'openssl library not installed' unless defined?(OpenSSL)
starttls
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
ssl.connect
@socket = Net::InternetMessageIO.new(ssl)
@socket.read_timeout = 60 #@read_timeout
@socket.debug_output = STDERR #@debug_output
do_helo(helodomain)

authenticate user, secret, authtype if user
@started = true
ensure
unless @started
# authentication failed, cancel connection.
@socket.close if not @started and @socket and not @socket.closed?
@socket = nil
end
end

def do_helo(helodomain)
begin
if @esmtp
ehlo helodomain
else
helo helodomain
end
rescue Net::ProtocolError
if @esmtp
@esmtp = false
@error_occured = false
retry
end
raise
end
end

def starttls
getok('STARTTLS')
end

def quit
begin
getok('QUIT')
rescue EOFError
end
end
end


(2)config/environments/development.rbにSMTPの設定追加

delevopment.rbの最後に追記

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:authentication => :plain,
:user_name => 'xxxxxx@gmail.com',
:password => '******'
}


(3)ActionMailer modelの生成

>script/generate mailer NotifyMailer result


(4)NotifyMailer modelの修正

def result(sent_at = Time.now)
subject 'NotifyMailer#result'
recipients 'xxxx@xxxxx.xxxx' #とりあえずここ修正
from 'xxxx@xxxxxx.xxx' #とりあえずここ修正
sent_on sent_at
body :greeting => 'Hi,'
end

(5)○○controllerにアクションの記述


def mail
mail = NotifyMailer.create_result()
NotifyMailer.deliver(mail)
end

(6)送信テスト
http://localhost:3000/xxx/mailにて送信出来るか確認。


[参考]
Ruby on Rails/ActionMailerでTLSを使ったメール送信

2009-01-14

Gedit をtextmate風にアレンジ

Linux(Ubuntu)でRailsの開発環境はどのようにしていますか?

NetBeansはなんか重くてイヤだし、
Emacsは挫折したし、vimでプログラムは・・って感じなんですよ。

軽くて簡単に使えるIDEないかなって探してたところ、
Macではtextmateが良いみたいなことを発見。

linuxでは、geditをtextmate風にアレンジ
出来るそうですね.

http://warlockhandler.blogspot.com/2008/04/converting-gedit-into-textmate.html


※ちなみにWindowsでは、e-text editorらしいよ。