Help request - Not sure how to implement an idea.
Hi, first of all thanks all for reading this :)
Let's say i would implement a kind of autosave form based on a calendar.
Let's sayt for each row of elements (pills) you have the last 7 days from the actual date columns, in every day there is a form field where you can input the amount of pills you have taken, and when you write down the number 2 5 8 it automatically writes down to db
prescription.create(Pill id X, date: xxx.xxxx, amount: xx)
i'm looking the autosave episode, but i'm kind of lost about the calendar option...
not sure if i've explained myself correctly :D
thanks all!
Just trying to understand things:
Your UI is basically a calendar. Each day (each box in the calendar) a user can enter how many pills s/he's taken for a particular medication.
Each time the user moves out of a day (by tabbing or pressing enter to move to the next day, for example), the number entered is saved to the db.
Is that right?
In other words, you don't want the user to have to explicitly click on a SAVE button.
Hi Ashley!, kind of. i'll try with a example :D
in the view it generates a list with the list of pills assigned to the person and when it writes on the box it automatically saves to db or draft the insert. that way is not necessary to do a button for each row.
today -5 today -4 today-3 today-2 today -1 Today
Pill A |1 _| |___| |2| |____| || |___|
today -5 today -4 today-3 today-2 today -1 Today
Pill B |____| |3| |_____| |1| |_| |___|
thanks!
The easiest way to do this is to have your front-end use Javascript to send the info to your Rails app. The Javascript will send it to your Rails app when it detects your user leaving the "box" for that pill on that day. (It'll be an 'on change' -type method in Javascript.)
If you don't have any experience with Javascript, you can read the Rails Guide (https://guides.rubyonrails.org/working_with_javascript_in_rails.html) and also watch the GoRails episodes that walk you through using Javascript + Rails. Here's one: https://gorails.com/episodes/clean-javascript-with-data-behavior) . Even though there have been improvements in Javascript & Rails+Javascript since that episode, the fundamentals are still the same. It -- and the episodes in that series -- explains the concepts and interactions well.
If you do have Javascript experience, then you can look for the GoRails episodes that use Vue or whatever framework you like. And I definitely recommend the Stimulus episodes, too.
(And BTW, it just so happens that I take a lot of pills to keep my body upright and functioning. So I think I have a decent idea of what your UI might look like. :-) )