Skip to content

Commit

Permalink
Merge pull request solidusio#3308 from softr8/dynamic-taxon-attachmen…
Browse files Browse the repository at this point in the history
…t-definitions

Making taxon form to render attachment definitions dynamically
  • Loading branch information
kennyadsl authored Sep 30, 2019
2 parents 06cda0a + 333c192 commit 58533d2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 1 addition & 5 deletions backend/app/views/spree/admin/taxons/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
</div>
<% end %>

<%= f.field_container :icon do %>
<%= f.label :icon %><br />
<%= f.file_field :icon %>
<%= image_tag f.object.icon(:mini) if f.object.icon_present? %>
<% end %>
<%= render "spree/admin/taxons/attachment_forms/#{f.object.attachment_partial_name}", f: f %>
</div>

<div class="col-5">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% f.object.class.attachment_definitions.each do |attachment, definition| %>
<%= f.field_container attachment do %>
<%= f.label attachment %><br>
<%= f.file_field attachment %>
<%= image_tag f.object.send(attachment, definition[:default_style]) if f.object.send(attachment).present? %>
<% end %>
<% end %>
4 changes: 4 additions & 0 deletions core/app/models/spree/taxon/paperclip_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ module Spree::Taxon::PaperclipAttachment
def icon_present?
icon.present?
end

def attachment_partial_name
'paperclip'
end
end

0 comments on commit 58533d2

Please sign in to comment.