「?」を含む値でフィールドを更新しようとすると、update_attributes は以下を返します。
**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' または 'test?' に変更されます。
- 「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! を使用すると、メッセージは (edit, still) になります。
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
rails 3.0.7 と mysql 0.2.7 に戻すことで修正されました。
考えられる原因:
「username」と「password」は、インターフェース テーブル内のフィールドです。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