ActiveRecordにto_hがないのは何か理由があるんですかね?
絶対あると思ったんですがありませんでした。
ruby
1class User < ApplicationRecord; end 2 3user = User.new(name: "foo", age: 10) 4user.to_h # {name: "foo", age: 10}が返ると予想 5 6NoMethodError: undefined method `to_h' for #<User:0x000055b87b863100> 7Did you mean? to_s 8from /usr/local/bundle/gems/activemodel-6.0.3.3/lib/active_model/attribute_methods.rb:432:in `method_missing'
attributes があるからではないでしょうか。
user.attributes
=> {"name"=>"foo", "age"=>10}