在编辑视图中显示附件 Rails 6(活动存储)
情况: 我成功地在我的表单部分“_a_partial.html.erb”中上传了一个名为:physical_copy的文件,该文件用于创建新对象并同时编辑现有对象
代码:
<%= f.file_field :physical_copy,
required: true,
class: 'form-control',
value: @tax_relevant_document.physical_copy %>
New &创建作品完美无缺。
问题: 该文件不会显示,因此在编辑时会被删除,这不是计划的行为。我可以通过先下载然后“重新上传”来解决这个问题,但这不应该是正常行为。
猜测: 这个“值”的东西对我来说看起来很不对劲,但删除该属性并没有帮助。
我想:
- 编辑视图以将字段中的现有文件名显示为基本值表示
- 形式表单应包含字段中的现有附件
Situation:
I sucessfully upload a file called :physical_copy in my form partial "_a_partial.html.erb", which is used for creating new objects and editing existing objects at the same time
Code:
<%= f.file_field :physical_copy,
required: true,
class: 'form-control',
value: @tax_relevant_document.physical_copy %>
New & create works perfectly fine.
Problem:
The file is not shown and hence deleted when editing, which is not the planned behavior. I can work around by first downloading and "re-uploading" but this shouldn't be the normal behavior.
Guess:
This "value" thing looks awry to me but removal of the attribute didn't help.
I would like:
- edit view to show the existing filename in the field as basically value representation
- the form should include the existing attachment in the field
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个解决方案并使其成为有条件的,在我的情况下效果很好:
基本上是下载附件!
I found a solution and made it conditional, which works fine in my case:
Basically the attachment for download!