0

Html code is:

Utilities: <br>
<input type="checkbox" name="amenity[utilities][]" value="Gas">Gas<br>
<input type="checkbox" name="amenity[utilities][]" value="Electricity">Electricity<br>
<input type="checkbox" name="amenity[utilities][]" value="Water">Water<br>
<input type="checkbox" name="amenity[utilities][]" value="Parking">Parking<br>

The above html is storing data in DB Table column as below:

--- 
- Gas
- Electricity
- Parking
- Water

enter image description here

1 Answer 1

1

This is because Rails serialize objects to YAML in order to store it in database. What you are seeing is actually a YAML serialized array. Here:

require 'yaml'
dbstr = "--- 
- Gas
- Electricity
- Parking
- Water"
# => "--- \n- Gas\n- Electricity\n- Parking\n- Water"
YAML::load dbstr
# => ["Gas", "Electricity", "Parking", "Water"]

Also check the doc for ActiveRecord::Base#serialize

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.