0

「?」を含む値でフィールドを更新しようとすると、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
4

2 に答える 2

1

私は同じエラーがありました。私にとっては、git バージョンを使用して修正した gem 'activerecord-jdbc-adapter' でした。

-gem 'activerecord-jdbc-adapter'
+gem 'activerecord-jdbc-adapter', :git => 'https://github.com/jruby/activerecord-jdbc-adapter.git'

これはこのコミットで修正されたようです: https://github.com/jruby/activerecord-jdbc-adapter/commit/837cd489591afbb24f6ba4d36a15a6c4da82b063

于 2011-10-27T20:14:41.963 に答える
0

エラーは ActiveRecord コールバックにあるようです。after_save やその他のコールバックで調べてみてください。どこかで nil オブジェクトに対して reverse 関数を使用しています。値に ? が含まれている場合、処理の結果として nil を取得している可能性があります。コールバック コードを投稿していただけると、より効果的です。

于 2011-06-05T17:38:58.760 に答える