I want to hide the packages included in drop down list without touching my model
I want to hide the packages included in drop down list without touching my model
I have a drop-down list which has to choose the packages. But currently, I want to hide some packages for now without touching my product model.
Please help me to solve this problem. Thanks!
<div class="col-sm-8 col-md-9">
<%= p.select :product_id, options_for_select( Listing::Product::PACKAGES.map { |k,v| [ v[:name], v[:rank] ] }, selected: p.object.product_id), {include_blank: true}, class: "form-control" %>
<small>
<%= p.label I18n.t('admin.listings.edit.configuration.select_product') %>
</small>
2 Answers
2
In the PACKAGES
constant kindly remove the not required items. Then write a separate method call from before_filter
. Inside that method add your additional items to the PACKAGES based on your condition(s).
PACKAGES
before_filter
To temporarily skip a few elements from packages collection, you can do this:
# app/helpers/application_helper.rb
def ignored_package_keys
%i[foo bar baz]
end
def packages_collection
Listing::Product::PACKAGES.dup.
delete_if { |k, _| ignored_package_keys.include? k }.
map { |_, v| [ v[:name], v[:rank] ] }
end
and in views:
<%= p.select :product_id, options_for_select(packages_collection, selected: p.object.product_id), { include_blank: true }, class: 'form-control' %>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment