2011-06-05 21 views
0

當我嘗試並使用含有的值更新的字段,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 
+0

一些代碼相關的錯誤/堆棧跟蹤將是有益的 – 2011-06-05 14:47:44

+0

試着用'運行的update_attributes它! '。這將引發異常(如果引發)並可能提供更有用的信息。 – Jits 2011-06-05 15:21:12

+0

你可以在Ruby 1.9.2的最新補丁集中試試這個嗎? – 2011-06-05 15:46:58

回答

0

看來錯誤是在一些ActiveRecord回調。嘗試在after_save或其他回調中查找它。某處您正在使用無效對象上的相反功能。當值包含?時,你可能會因爲處理而得到零。如果您發佈回叫代碼,我們可以提供更好的幫助。

+0

我想這可能不是原因,但我會更新我的帖子與base_controller的內容。正如我在注意到你的回覆之前對Zameer說的那樣,我通過恢復到rails 3.0.7和mysql2 0.2.7來修復錯誤。 – Cookies 2011-06-05 21:03:14