2
undefined method `reject' for "4":String
當我嘗試執行@ user.update_attributes(params)時拋出。activerecord-2.3.14用ruby打破1.9.2 ::未定義的方法`拒絕'爲「4」:字符串
】這個params名單如下
"user"=>{"login"=>"admin", "first_name"=>"Admin", "last_name"=>"Admin", "email"=>"[email protected]", "location_id"=>"1", "last_login_at_text"=>"Never logged in", "password"=>"", "password_confirmation"=>"", "role_ids"=>"4", "active"=>"true", "is_staff"=>"true"},
錯誤堆棧如下
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14 /lib/active_record/associations.rb:1336:in block in collection_accessor_methods'
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/lib/active_record/base.rb:2918:inblock in assign_attributes'
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/lib/active_record/base.rb:2914:in each'
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/lib/active_record/base.rb:2914:inassign_attributes'
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/li b/active_record/base.rb:2787:in attributes='
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/lib/active_record/base.rb:2671:inupdate_attributes_inside_transaction'
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/lib/active_record/transactions.rb:229:in block in with_transaction_returning_status'
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/database_statements.rb:136:intransaction'
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/lib/active_record/transactions.rb:182:in transaction'
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/lib/active_record/transactions.rb:228:inwith_transaction_returning_status'
/home/narendra/.rvm/gems/[email protected]_schedule/gems/activerecord-2.3.14/lib/active_record/base.rb:2667:in update_attributes'
/home/narendra/workspace/nf_schedule/app/controllers/users_controller.rb:100:inupdate'
我認爲這打破了作爲字符串的紅寶石1.9.2不混入「可枚舉」。 任何人都可以確認這是一個問題還是我錯過了什麼?
https://github.com/rails/rails/issues/3434
該參數是由表單提交生成的。我希望主動記錄應該優雅地處理這一點。在代碼中無處不在的代碼 – naren
這樣的代碼不會很好。你不應該修補ActiveRecord來處理不良的表單提交。你不應該以這種方式發送結構化數據,所以它首先在它的工作方面令人驚訝。 – tadman
這在Ruby 1.8.7和rails 2.3.14中工作得很好。我在遷移到Ruby 1.9.2時遇到了這個問題。我相信對於我正在使用的單選按鈕,軌道用於處理的方式(所選選項以字符串形式發送)。我不知道是否有幫助將單選按鈕輸入格式化爲數組元素而不是字符串(例如:role_ids「=> [」4「]而不是role_ids」=>「4」)。所以你認爲它仍然是一個糟糕的表單提交或單選按鈕幫手應該修復? – naren