Skip to content

Commit

Permalink
Store property list in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Willianvdv committed Dec 6, 2013
1 parent fea907c commit 20a58d8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
15 changes: 15 additions & 0 deletions app/controllers/spree/admin/taxons_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Spree::Admin::TaxonsController.class_eval do
before_filter :split_taxon_ids, only: [:new, :update]

private
# todo: rework this. Don't permit all params
def taxon_params
params.require(:taxon).permit!
end

def split_taxon_ids
if params[:taxon][:property_ids].present?
params[:taxon][:property_ids] = params[:taxon][:property_ids].split(',')
end
end
end
6 changes: 3 additions & 3 deletions app/views/spree/admin/taxons/_taxons_filters.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="twelve columns alpha omega">
<%= @taxon.taxon_filter_ids %>
<%= f.field_container :taxon_filters do %>
<%= f.text_field :taxon_filter_ids, value: @taxon.taxon_filter_ids.join(',') %>
<%= f.field_container :properties do %>
<%= f.label :properties, Spree.t(:filterable_properties) %><br />
<%= f.text_field :property_ids, value: @taxon.property_ids.join(',') %>
<% end %>
</div>
1 change: 1 addition & 0 deletions config/initializers/hstore_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Spree::PermittedAttributes.taxon_attributes << :property_ids
6 changes: 4 additions & 2 deletions spec/models/spree/taxon_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
describe Spree::Taxon do
let(:taxon) { FactoryGirl.create :taxon }
let(:property) { FactoryGirl.create :property }
let(:property2) { FactoryGirl.create :property }


describe 'no taxon filters are defined' do
it 'creates taxon filters' do
taxon.property_ids = [property.id,]
expect(taxon.properties).to eq([property])
taxon.property_ids = [property.id, property2.id]
expect(taxon.properties).to eq([property, property2])
end
end

Expand Down

0 comments on commit 20a58d8

Please sign in to comment.