16
這裏是從導向簡短片段上的ActionMailer的ActionMailer實例方法
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
def welcome_email(user)
@user = user
@url = "http://example.com/login"
mail(:to => user.email,
:subject => "Welcome to My Awesome Site")
end
end
和Controller
class UsersController < ApplicationController
# POST /users
# POST /users.xml
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
# Tell the UserMailer to send a welcome Email after save
UserMailer.welcome_email(@user).deliver
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
end
那麼,爲什麼Rails的試圖混淆與實例方法rubyist作爲類方法?我認爲他們已經重寫了缺少的方法,但它只是用來混淆!或者我在這裏錯過了什麼?
即爲什麼不定義爲welcome_email高清自 .welcome_email(用戶)
那麼,當調用郵件程序時,rails應該繼續在方法名前加上'create'或'deliver'。貶低那些(Rails3)支持瘋狂的vudoo只會創造出瘋狂的低調開發者,他們認爲他們知道紅寶石,但他們真的沒有 –
你有問題,或者只是想表達你的意見? ;)你似乎創造了一個帶有修辭問題的話題,你不應該這樣做,並且可能會被關閉。 – d11wtq
這是一個問題 - 但基於它的'巫術'的答案,而不是一些真正的邏輯理由 - 我想它確實看起來不相關。 –