2
undefined method `reject' for "4":String
は、@ user.update_attributes(params)を実行しようとするとスローされます。エラー・スタックが、私は、これは「列挙」ミックスインしませんルビー1.9.2に文字列として壊れると仮定activerecord-2.3.14 rubyで1.9.2 ::定義されていないメソッド "reject" for "4":文字列
/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'
以下の通りです
"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"},
を次のように
のparamsリストがあります。 これが問題であるか誰かが何か不足していることを誰でも確認できますか?
https://github.com/rails/rails/issues/3434
paramsはフォーム送信によって生成されます。私はactiverecordがこれを優雅に処理することを願っています。コード内のどこにでもこのようなコードをパッチするのは良いことではありません – naren
悪いフォームの送信を処理するためにActiveRecordにパッチを当てるべきではありません。あなたはそのように構造化されたデータを送信することは想定されていないので、それは最初は全く驚くべきことです。 – tadman
これはruby 1.8.7とレール2.3.14で完璧に機能しました。私はruby 1.9.2に移行したときに問題に直面しています。私はそれを使用しているラジオボタンのために、それはどのように扱うために使用されたレール(選択されたオプションは文字列として送信されます)と考えています。ラジオボタンの入力を文字列ではなく配列要素としてフォーマットするためのヘルパーがあるかどうかはわかりません(例:role_ids "=" "4"の代わりにrole_ids "=> [" 4 "])。だからあなたはまだそれが悪いフォームの提出やラジオボタンのヘルパーが修正されるべきだと思いますか? – naren