いつも忘れるのでメモ。

###mailerオプション
script/generate mailer class_name method_name
shell>>
$ rails -v
Rails 2.0.2
$ script/generate mailer TestMailer welcome
exists app/models/
create app/views/test_mailer
exists test/unit/
create test/fixtures/test_mailer
create app/models/test_mailer.rb
create test/unit/test_mailer_test.rb
create app/views/test_mailer/welcome.erb
create test/fixtures/muji_mailer/welcome
<<--
viewは***.erb**形式なんですね。

###添付とbodyにURLを追加する時の注意

  • URLをbodyに渡すにはurl_forが使えます。

  • attachmentはメソッドなので@はいりません(ココはまりました)。

  • ファイルを複数添付の時はattachmentを複数回呼べばOKです。
    rails>>
    @body = {:sender => "satoko",
    :message => "welcome",
    :s21g_url => url_for(:host => "www.s21g.com", :controller => "top", :action => "index")
    }

    attachment :content_type => "image/png",
    :body => File.read("an-image.png"),
    :filename = "test.png"

    attachment :content_type => "image/png",
    :body => File.read("an-image2.png"),
    :filename = "test2.png"

<<--

###generatorのmailerヘルプ
下記でコマンドでヘルプが表示できます
shell>>
$ script/generate mailer --help
<<--

###Refs
http://wota.jp/ac/?date=20050731
http://rails-recipebook.g.hatena.ne.jp/rrbk/?word=*%5BMail%5D

posted by satoko satoko on Thu 17 Apr 2008 at 11:14 with 0 comments