I''m developing database systems for clinical trials using Ruby on Rails. Some trials require ''double data entry'' as a form of validation; I need to incorporate this into my system and am having difficulties. My plan would be to have it work as follows: - Once a new record has been created, alongside the usual ''edit'' option there would be a ''second data entry'' option. - On clicking this, a ''blank'' record would appear (as if a new record) - but when submitted, this form data would be compared with the existing record on the database. - If any differences were found this form would be displayed again with the relevant fields highlighted (à la validation, with the accompanying text showing the previous values) and the user asked to confirm. - After confirmation (or if the second input exactly matched the first initially) the reocrd would be saved and a flag will be set in the table that double data entry has been performed for that record. Hopefully this could be handled in the same (edit) method by passing a parameter (data_entry_mode or something). Ideally the second version would not involve creating a new record in the database; any changes would simply be written over the top of the first (perhaps the second data entry values would be stored as session variables??). Does anyone have any ideas on how best to accomplish this? I apologise for the long and unusual nature of this query. Thank you for any thoughts. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Oct 16, 6:39 am, Tim Chater <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''m developing database systems for clinical trials using Ruby on Rails. > Some trials require ''double data entry'' as a form of validation; I need > to incorporate this into my system and am having difficulties. My plan > would be to have it work as follows: > > - Once a new record has been created, alongside the usual ''edit'' option > there would be a ''second data entry'' option. > - On clicking this, a ''blank'' record would appear (as if a new record) - > but when submitted, this form data would be compared with the existing > record on the database. > - If any differences were found this form would be displayed again with > the relevant fields highlighted (à la validation, with the accompanying > text showing the previous values) and the user asked to confirm. > - After confirmation (or if the second input exactly matched the first > initially) the reocrd would be saved and a flag will be set in the table > that double data entry has been performed for that record. > > Hopefully this could be handled in the same (edit) method by passing a > parameter (data_entry_mode or something). Ideally the second version > would not involve creating a new record in the database; any changes > would simply be written over the top of the first (perhaps the second > data entry values would be stored as session variables??). > > Does anyone have any ideas on how best to accomplish this? > > I apologise for the long and unusual nature of this query. Thank you for > any thoughts. > > -- > Posted viahttp://www.ruby-forum.com/.Hi Tim, First off, I have an interest in this sort of application myself. Please contact me off-list if you would like additional help. The proper way to do double entry rather depends on your workflow. * Do you have the same person enter the data twice? * Does the second entry happen at a different time, or do you want to do it all in one form? As a general rule, double entry makes for a bad user interface, but there are times when it is necessary (password verifications show up a lot). In any event, one way to implement this would be through an ''edit'' like action. - record has been entered - user invokes the ''verify'' action on the record. - ''verify'' generates a blank form (much like a new item form) but passes the id of the record in a hidden field - on submission, load the original object in memory - cycle through all the attributes of the record looking for differences. Ignore at ''created_at'' like attributes. - If all the relevant columns pass, then update the ''verified_at'' with the timestamp of when it passed the test. - If not, then assign the ''errors'' for the record and re-render the form with the discrepancies highlighted. _Kevin www.sciwerks.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi Kevin> First off, I have an interest in this sort of application myself. > Please contact me off-list if you would like additional help.Thank you. I expect I shall do so soon!> * Do you have the same person enter the data twice?No.> * Does the second entry happen at a different time, or do you want to > do it all in one form?A different time. (The idea being that double data entry can be used as an extra for some forms in some studies - and perhaps only for a sample of the records, with a status flag to indicate if a given record has been entered twice.)> In any event, one way to implement this would be through an ''edit'' like > action. > > - record has been entered > - user invokes the ''verify'' action on the record. > - ''verify'' generates a blank form (much like a new item form) but > passes the id of the record in a hidden field > - on submission, load the original object in memory > - cycle through all the attributes of the record looking for > differences. Ignore at ''created_at'' like attributes. > - If all the relevant columns pass, then update the ''verified_at'' with > the timestamp of when it passed the test. > - If not, then assign the ''errors'' for the record and re-render the > form with the discrepancies highlighted.This is exactly the sort of process flow that I''m after! Now I just need to work out the code. I shall have a go, but any help on these pages would be appreciated (especially as, ideally, this might end up as a plugin so that there wouldn''t be the need to write the same code in every edit method!). -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Just a thought, my acts_as_modified plugin may be of use to you when looking for differences between the records. You could assign the new values to the original record then use record.modified_attributes see any differences. http://svn.viney.net.nz/things/rails/plugins/acts_as_modified -Jonathan. On 10/17/06, Tim Chater <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi Kevin > > > First off, I have an interest in this sort of application myself. > > Please contact me off-list if you would like additional help. > > Thank you. I expect I shall do so soon! > > > * Do you have the same person enter the data twice? > > No. > > > * Does the second entry happen at a different time, or do you want to > > do it all in one form? > > A different time. (The idea being that double data entry can be used as > an extra for some forms in some studies - and perhaps only for a sample > of the records, with a status flag to indicate if a given record has > been entered twice.) > > > In any event, one way to implement this would be through an ''edit'' like > > action. > > > > - record has been entered > > - user invokes the ''verify'' action on the record. > > - ''verify'' generates a blank form (much like a new item form) but > > passes the id of the record in a hidden field > > - on submission, load the original object in memory > > - cycle through all the attributes of the record looking for > > differences. Ignore at ''created_at'' like attributes. > > - If all the relevant columns pass, then update the ''verified_at'' with > > the timestamp of when it passed the test. > > - If not, then assign the ''errors'' for the record and re-render the > > form with the discrepancies highlighted. > > This is exactly the sort of process flow that I''m after! Now I just need > to work out the code. I shall have a go, but any help on these pages > would be appreciated (especially as, ideally, this might end up as a > plugin so that there wouldn''t be the need to write the same code in > every edit method!). > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I''ve had a go at writing a verify method... def verify @subject = Subject.new @subject.id = params[:id] if request.post? @subject_original = Subject.find(params[:id]) #load original record changes = [] #array to store changes @confirm = true #when form is submitted, change button to ''Confirm'' @subject_original.attributes.each do |key, value| if params[:subject][key] @transaction = record_transaction(''subjects'', key, @subject_original.id, value, params[:subject][key], value.class.to_s) changes << @transaction if @transaction #write any changes into array end end case params[''commit''] when "Next" then for change in changes @subject.errors.add(change.field, change.old_value.to_s) end when "Confirm" then @subject_original.update_attributes(params[:subject]) @subject_original.save end end end This uses a method called ''record_transaction'' from my application controller to only add to the changes array if there has been a change. Jonathan - I''m sure that your plugin would be useful here for doing the comparisons and building up the changes array instead of using record_transaction - can you give me any help as to how I''d fit it into the code above? When the verification form is submitted, the page is currently redisplayed with any differences shown as if they were validation errors. (And the ''next'' button changes to ''confirm'' so that the next form submission writes to the DB.) Rather than validation errors, is there an easy way for me to write something such that I can do @subject.verifications.add(...), which would work a bit like the Automatic Rails validation, but, as well as highlighting fields with differences, display the old values next to each differing field? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
The docs should be enough: http://svn.viney.net.nz/things/rails/plugins/acts_as_modified/lib/acts_as_modified.rb But just quickly, you can do: @subject = Subject.find(params[:id]) @subject.attributes = { :name => "New name" } @subject.modified_attributes # { :name => "Old name" } @subject.name_modified? # true @subject.original_name # "Old Name" @subject.modified? # true Feel free to email me off-list if you want more assistance with the plugin. -Jonathan. On 10/20/06, Tim Chater <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''ve had a go at writing a verify method... > > def verify > @subject = Subject.new > @subject.id = params[:id] > > if request.post? > @subject_original = Subject.find(params[:id]) #load original > record > changes = [] #array to store changes > @confirm = true #when form is submitted, change button to > ''Confirm'' > @subject_original.attributes.each do |key, value| > if params[:subject][key] > @transaction = record_transaction(''subjects'', key, > @subject_original.id, value, params[:subject][key], value.class.to_s) > changes << @transaction if @transaction #write any changes > into array > end > end > > case params[''commit''] > when "Next" then > for change in changes > @subject.errors.add(change.field, change.old_value.to_s) > end > when "Confirm" then > @subject_original.update_attributes(params[:subject]) > @subject_original.save > end > end > end > > This uses a method called ''record_transaction'' from my application > controller to only add to the changes array if there has been a change. > Jonathan - I''m sure that your plugin would be useful here for doing the > comparisons and building up the changes array instead of using > record_transaction - can you give me any help as to how I''d fit it into > the code above? > > When the verification form is submitted, the page is currently > redisplayed with any differences shown as if they were validation > errors. (And the ''next'' button changes to ''confirm'' so that the next > form submission writes to the DB.) Rather than validation errors, is > there an easy way for me to write something such that I can do > @subject.verifications.add(...), which would work a bit like the > Automatic Rails validation, but, as well as highlighting fields with > differences, display the old values next to each differing field? > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks Jonathan. This has saved me several lines of code and works a treat! What an excellent plugin. Tim -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---