简体   繁体   中英

Why am I getting the “can't modify frozen String” error when I am not modifying the hash?

I am getting the can't modify frozen String error on the User.create(name:name,email:email) . But I am not modifying the hash at all. All I am doing is creating a new User object with the hash name and email . I am not modifying them. Can someone please clarify as to why I am getting this? Thank you!

Code:

users = {'John' => 'john@john.com', 'Sara' => 'sara@sara.com'}
def create_users_from_hash(users)
  users.each do |name, email|
    User.create(name:name,email:email)
  end
end

You can use create! to find where is wrong.Sometimes error will be raised when you want to access an inaccessiable field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM