-1
class ApplicationController < ActionController::Base
private
# Finds the User with the ID stored in the session with the key
# :current_user_id This is a common way to handle user login in
# a Rails application; logging in sets the session value and
# logging out removes it.
def current_user
@_current_user ||= session[:current_user_id] &&
User.find_by_id(session[:current_user_id])
end
end
如何理解上面的代碼? ||=
是什麼意思?並且是@_current_user
一個id或一個用戶對象?另外,爲什麼它始於_
?什麼是|| =在rails中?
任何人都可以回答我@_current_user
是什麼?
該帖子的答案不好。它不回答關於'@ _current_user'的其他問題。 – OneZero
http://stackoverflow.com/questions/8506257/operator-in-ruby-搜索「ruby運營商」。 – 2013-03-31 00:22:47