You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you try to edit a ticket that had file(s) attached when it was created or from a previous edit app will break. Look at the following error! The edit form is setting new rows (equal to the number of files previously uploaded) in the assets table with asset attribute & content_type to [null]! It shouldn't do that! Is duplicating rows with asset & content_type to null! It should be keeping (not replacing) files on nested edits. There ought to be an "if new_record? do this else do that" somewhere in the form view! As well the file number count it ain't right in the edit form when adding more files on top of previously attached files!! Plus when editing the <%= asset.label :asset, "File ##{number += 1}" %> line doesn't work properly!!
The text was updated successfully, but these errors were encountered:
eriol12
changed the title
app broken after editing ticket if it had a previous attached file!
app broken after editing ticket if it had previously uploaded file(s)
Nov 18, 2014
I think this would be a better option. When you update a ticket it ought to list all the previously attached files with the ability to destroy them plus having the option to add more files.
Below is the setup i have for this particular scenario:
# views/tickets/show.html.erb file
...
<% if@ticket.assets.present?%> <h4>AttachedFiles</h4> <div class="assets"> <% @ticket.assets.each do |asset| %> <%= link_to file_path(asset) do %> <%= File.basename(asset.asset.path.to_s) %> <% end %> <small><%= number_to_human_size(asset.asset.size) %></small>
<% end %>
</div>
<% end %>
# files/_form.html.erb file
<%= fields_for@ticketdo |f| %> <%= f.fields_for :assets, child_index: number do |asset| %>
<% if asset.object.new_record? %> <%= asset.file_field :asset %> <% end %> <% end %> <%= f.fields_for :assets do |asset| %> <% unless asset.object.new_record? %> <%= File.basename(asset.object.asset.url.to_s) %> <%= asset.check_box :_destroy %> <% end %> <% end %> <% end %>
The code can be seen on the working branch at: https://github.com/eriol12/ticketee_review.git
If you try to edit a ticket that had file(s) attached when it was created or from a previous edit app will break. Look at the following error! The edit form is setting new rows (equal to the number of files previously uploaded) in the assets table with asset attribute & content_type to [null]! It shouldn't do that! Is duplicating rows with asset & content_type to null! It should be keeping (not replacing) files on nested edits. There ought to be an "if new_record? do this else do that" somewhere in the form view! As well the file number count it ain't right in the edit form when adding more files on top of previously attached files!! Plus when editing the
<%= asset.label :asset, "File ##{number += 1}" %>
line doesn't work properly!!The text was updated successfully, but these errors were encountered: