I have a nested form for an object in which there may be many files, I have no problem in the creation of an object, but When I have to edit it, I know the problem, the form URL should be a link to the URL, but I do not know how to reference the file itself. I am using paperclip in this case if there was only one file And this object I was in the model then I would do something like @ object.file.url, but since there are many files, I do not know how to proceed in this case ...
edit.html Haml object_form.html.haml file_fields.html.ahm I'm trying to clearly define file_fields.html .aml I think you should be able to do like this: = form_for @object ,: url = & gt; {: Action = & gt; "Update" ,: Admin = & gt; "Object" ,: id = & gt; @ Object.id,: method = & gt; "Post"},: html = & gt; {: Multipurpose = & gt; True} what? F | - object: f.object, f: f
render object / object object ". Field = f.label: name = f.text_field: name = f.fields_for: files do | builder | = render 'object / files_filends' ,: f = & gt; builder% p = link_to_add_fields "add new file", f, : File.field = f.submit "save"
% fieldset .field = f .label: file = f.file_field: file .field = f.hidden_field: _destroy = link_to "Remove file", '#', category: "remove_fields"
% f Ieldset .field = f does not work .label: file = f.file_field: file = link_to f.file.url.field = f.hidden_field: _destroy = link_to "Remove file", '#', class: "remove_fields "
f.object.url
% fieldset .field = f.label: file = f.file_field: file # fixed It is not that it will generate neil error on Neil form. # Given how the F object will not have a URL yet - if f.object.url = link_to f.object.url.field = f.hidden_field: _destroy = link_to "Remove File", '#', Class: "remove_fields "
No comments:
Post a Comment