Reputation: 27
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
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 Holiday
s
holiday = Holiday.new
holiday.days = ["", "monday", "tuesday"]
holiday.count = 2
Then all you need to do is save it:
holiday.save
Upvotes: 1