Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editable submissions #248

Closed
lmkw opened this issue Nov 4, 2019 · 6 comments · Fixed by #368
Closed

Editable submissions #248

lmkw opened this issue Nov 4, 2019 · 6 comments · Fixed by #368

Comments

@lmkw
Copy link
Contributor

lmkw commented Nov 4, 2019

  • Save for later
  • Editable file uploads

5 votes

@lmkw
Copy link
Contributor Author

lmkw commented Jan 8, 2020

@fanglinnw , can you weigh in on this? We're looking for possible short-term solutions so users can save and come back to their submissions. John has more information on why the file uploads complicate this ticket, but this is assigned to Matt

@fanglinnw
Copy link
Contributor

fanglinnw commented Jan 9, 2020

@mattbaumann1 @jseraf Gary has a work-around in the Membership app for the known issue in ActiveStorage of losing file uploads during edit. Here's the relevant code:
https://github.com/NUARIG/membership/blob/a7140dc5c66a39243994f6038da354eb6bbcdae4/app/controllers/program_membership_applications_controller.rb#L131-L141

Membership allows applicant to save file uploads in an application that's not submitted. So I think this is possible in Competition too.

@lmkw lmkw added this to To do in 20200127 Eponymous Sprint via automation Jan 13, 2020
@fanglinnw
Copy link
Contributor

Note: please don't use the above code I linked in Membership because it has a serious bug that's causing . me great pain right now.

@fanglinnw
Copy link
Contributor

fanglinnw commented Jan 17, 2020

here's what I figured out so far. To preserve the previously uploaded file, you need to add a hidden field before the file_field, and turn on the direct_upload option on the field_field:

<%= form.hidden_field :file, value: form.object.file.signed_id if form.object.file.attached? %>
<%= form.file_field :file, direct_upload: true %>

It's important to place the hidden_field before the file_field to allow updating existing upload (the last param with the same key takes precedence and this behavior is ensured because that's how the check_box field works in Rails, see the "Gotcha" secion in https://apidock.com/rails/ActionView/Helpers/FormHelper/check_box).

With this, you don't need to do any hack in the controller for the "create" action.

for the "update" action, if the file is on a nested child record, there's a known issue (rails/rails#37701) of not attaching new file during updates on the parent object. you can add a work-around on the child model like this:

class Parent
  has_many :children
  accepts_nested_attributes_for :children
...
end

class Child
  belongs_to :parent
  has_one_attached :file
  ...
  def changed_for_autosave?
    super || file.changed_for_autosave?
  end
end

@mattbaumann1
Copy link
Collaborator

In some initial testing the changed_for_autosave? method does not seem like it is necessary in Rails 5 but @fanglinnw says that it will be required in Rails 6.

@lmkw lmkw moved this from To do to In progress in 20200127 Eponymous Sprint Jan 27, 2020
@lmkw lmkw added this to In progress in 20200210 life's rich pageant Jan 27, 2020
@lmkw lmkw added the 10 days Time: 2 Weeks label Jan 29, 2020
@firaswehbe
Copy link
Member

Per discussion on 2/3/2020 -- saving a draft would require all the validations on the form that would be required on submission. We can revisit relaxing that later.

mattbaumann1 added a commit that referenced this issue Feb 10, 2020
mattbaumann1 added a commit that referenced this issue Feb 10, 2020
mattbaumann1 added a commit that referenced this issue Feb 11, 2020
This includes adding the HTML checks back on the fields.
mattbaumann1 added a commit that referenced this issue Feb 11, 2020
@mattbaumann1 mattbaumann1 moved this from In progress to Done in 20200210 life's rich pageant Feb 11, 2020
@firaswehbe firaswehbe linked a pull request Feb 11, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants