1
你好,我已經在我的創建控制器如下:軌道3 - 幫助返回一個零
def create
@requestable = find_requestable
if [email protected]?
. ..
然後:
def find_requestable
params.each do |name, value|
if name =~ /(.+)_id$/
return $1.classify.constantize.find(value)
end
end
nil
end
這個工程發現當find_requestable發回paratemter,但如果它是不是它不發回一個導致一切錯誤的NIL:
NameError (uninitialized constant Undefined):
app/controllers/request_threads_controller.rb:133:in `find_requestable'
app/controllers/request_threads_controller.rb:131:in `each'
app/controllers/request_threads_controller.rb:131:in `find_requestable'
app/controllers/request_threads_controller.rb:52:in `create'
app/middleware/flash_session_cookie_middleware.rb:14:in `call'
爲什麼不find_requestable發回零?謝謝
不錯的主意,但同樣的錯誤 – AnApprentice 2010-11-13 18:52:31
在你的方法,哪一行是133? – John 2010-11-13 18:54:19
return $ 1.classify.constantize.find(value) – AnApprentice 2010-11-13 18:56:45