I have a prescription model in my Rails 3 application. I am trying to work out the best method of allowing records to be duplicated, but allowing the user to \"review\" the
To do this, you're going to have to create a new instance of your Prescription class. "dup" works, but you're assuming it overwrites the existing record. Only methods that end with a bang(!) tend to do that.
Your code should be:
def clone
@prescription = Prescription.find(params[:id])
@new_prescription = @prescription.dup
@new_prescription.save
end
or
def clone
@prescription = Prescription.find(params[:id]).dup
@prescription.save
end
This isn't testing for times when the :id isn't found.