简体   繁体   中英

Ruby on Rails multidimensional array-like storage

I'm trying to create a form that has:

TextInput --Skill

DropDown --Years Experience

Using jQuery, I have the input and drop down fields populate if a user has more skills to add. Is it possible to store many sets of skills and their respective years experience in a database entry?

I've been looking into has_many:

Thank you!

No need for extra query here (has_many), look into rails serialization:

class User < ActiveRecord::Base
  serialize :preferences, Hash
end

user = User.create(:preferences => { "background" => "black", "display" => "large" })
User.find(user.id).preferences # => { "background" => "black", "display" => "large" }

You can do the same with Array

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