當我嘗試並使用含有的值更新的字段,update_attributes方法返回「?」:update_attributes方法NoMethodError當表單值包含問號軌3.1
**NoMethodError**
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.reverse
我的控制器能夠:
- 用'?'創建記錄作爲字段名稱。
- 如果包含'?'的字段編輯/保存記錄保持不變
- 如果包含'?'的字段編輯/保存記錄更改爲「測試」
不能:
- 編輯/保存記錄,如果包含場「?」更改爲'?測試'或'測試?'
- 如果包含'test'的字段更改爲'?',編輯/保存記錄
我想active_record忽略不變的字段,這就是爲什麼代碼在這種情況下工作。
我也在日誌中看到BEGIN和ROLLBACK,所以我認爲錯誤是由update_record在將字符串傳遞給數據庫之前無法引用字符串引起的。這是一個錯誤還是我應該明確引用表單輸入?
我的更新方法:
def update
@interface = Interface.find(params[:id])
if @interface.update_attributes(params[:interface])
redirect_to :action => 'show', :id => @interface.id
else
redirect_to :action => 'edit'
end
end
的模型是空白。
使用!update_attributes方法的消息是(編輯,仍然):
NoMethodError in Admin::InterfacesController#update
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.reverse
對不起,我提到了引發ArgumentError是無關緊要的。
原始堆棧跟蹤:http://pastebin.com/JQ3Cmrba
通過恢復到軌道3.0.7和MySQL 0.2.7固定。
可能原因:
'用戶名'和'密碼'是接口表中的字段。 interface_controller繼承自一個base_controller:
class Admin::BaseController < ApplicationController
layout 'admin'
before_filter :authenticate
def index
end
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
if username == 'test' and password == 'pass'
true
else
false
end
end
end
end
一些代碼相關的錯誤/堆棧跟蹤將是有益的 – 2011-06-05 14:47:44
試着用'運行的update_attributes它! '。這將引發異常(如果引發)並可能提供更有用的信息。 – Jits 2011-06-05 15:21:12
你可以在Ruby 1.9.2的最新補丁集中試試這個嗎? – 2011-06-05 15:46:58