[RoR ] Functional test 有問題

看板Ruby作者 (嗯....?)時間18年前 (2007/12/03 12:56), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/3 (看更多)
目前需為已存在的 Ruby on Rails code 寫 Testing 但在寫某個 test_update 時卻碰上了問題 原程式將 update 的 validate 寫在 controller 中 節錄一小段 if params[:user][:clear_password] and params[:user][:clear_password].length > 0 and params[:user][:confirm_password] != params[:user][:clear_password] flash[:error] = 'Password invalid!' render :action => 'edit' 當我測試密碼兩者輸入不同時 卻會在執行到 render 的地方跳出 exception Exception: You have a nil object when you didn't expect it! The error occured while evaluating nil.site_name On line #43 of app/views/layouts/application.rhtml 40: <body> 41: <div class="header"> 42: <img src="/images/logo.jpg"/> 43: <h1><%= @settings.site_name %></h1> 44: <h2><%= @settings.site_subtitle %></h2> 45: </div> 46: <div class="navbar"> 可以請高手幫忙看看是什麼問題嗎? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 65.190.196.191

12/03 15:33, , 1F
很單純的就是 @settings 是 nil 所以無法找到 site_name
12/03 15:33, 1F

12/03 21:05, , 2F
是的 我沒有說的很清楚 我知道是@setting變為nil
12/03 21:05, 2F

12/03 21:06, , 3F
我想請問有沒有辦法可以避免
12/03 21:06, 3F
文章代碼(AID): #17KuoPhd (Ruby)
文章代碼(AID): #17KuoPhd (Ruby)