Anu
Anu

Reputation: 27

how to save the field in database

How to save the field containing like "holiday"=>["", "monday", "tuesday"] in to the database?

These can be selected from drop down{multiple selection}.

I added the multiple selection with jquery and found difficulty in saving part.

Upvotes: 1

Views: 191

Answers (1)

David Klinge
David Klinge

Reputation: 360

Rails works best if you work within the framework and convention.

You can create a model for your Holiday by running:

rails generate model holiday days:string count:integer

This will create a Holiday model that inherits from ApplicationRecord with the string property days and the integer property count at the path:

app/models/holiday.rb

You need to update your database by running the following at the command line:

rake db:migrate

And now you can create, validate, and save Holidays

holiday = Holiday.new
holiday.days = ["", "monday", "tuesday"]
holiday.count = 2

Then all you need to do is save it:

holiday.save

Upvotes: 1

Related Questions