Skip to content

Commit

Permalink
Making taxon form to render attachment definitions dynamically
Browse files Browse the repository at this point in the history
Solidus now allows to inject easily more attachment definitions via
configurable modules, if a user adds a new attachment, it would have
to override the partial _form to add this new attachment, this change
takes all definitions and render the inputs dinalycally, it also allows
to specify what partial to render depending on the attachment adapter.
  • Loading branch information
softr8 committed Aug 29, 2019
1 parent df79573 commit 333c192
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 333c192

Please sign in to comment.