所以,我對於登錄獲取渲染認識到定製的路由路徑
# routes.rb
map.login '/login', :controller => 'sessions', :action => 'new'
訪問www.asite.com/login時髦的定製路線,你在那裏。但是,如果用戶登錄失敗,我們會在我們的操作中執行以下操作。注意登錄失敗時會發生什麼。
# sessions_controller.rb
def create
self.current_user = User.authenticate(params[:email], params[:password])
if logged_in?
# some work and redirect the user
else
flash.now[:warning] = "The email and/or password you entered is invalid."
render :action => 'new'
end
end
這是非常典型的。只需呈現新操作並提示再次登錄。不幸的是,你也會得到一個醜陋的網址:www.asite.com/session。伊克!是否有可能得到渲染尊重原始網址?
不好的例子。考慮你希望用戶已經填寫到表單中的文本被保留的情況。渲染是這樣做的(因爲對象是部分構建的)。重定向失去狀態。 – 2008-10-23 21:45:46