例えば
@post = Post.new
temp = JSON.parse(@post.to_json)
#=> {id:nil, title:nil, body:nil, created_at:nil, updated_at:nil}
Post.new(tmp)
ってやるとid
やcreated_at
, updated_at
などがMass assignment securityに引っかかる
必要なものだけのHash(title
とbody
だけ)にしてやりたいなら、ActiveSupportのHash#slice
をつかう
Post.new(tmp.slice(*Post::accessible_attributes) #=> true