ruby on rails - Use activeadmin-ajax_filter gem in nested forms -
i'm using activeadmin admin panel. in nested form, need use filtering, example, in dropdown need select option name, , in second dropdown should displayed option's values. this, want use activeadmin-ajax_filter gem. option , optionvalue connected each other: option has_many :option_values, , optionvalue belongs_to option. create option_values through nested form when create option. then, have product model, in via nested form create variant. so, variant belongs_to :option_value belongs_to :product , optionvalue has_many :variants, product has_many :variants. now, when want create new variant, can select option values have in db, want do, select option (for example size), , then, in dropdown below - select appropriate values (xl, s, , on). code active_admin resources is:
activeadmin.register product permit_params :category_id, :name, :description, :short_description, :image, :subtitle, product_currencies_attributes: [:id, :product_id, :currency_id, :price, :_destroy], variants_attributes: [:id, :product_id, :in_stock_id, :sold_out_id, :option_value_id, :image, :visible, :orderable, :_destroy] index column :id column :image |product| image_tag(product.image.url(:thumb)) if product.image end column :category_id |product| category = category.find(product.category_id) link_to category.name, admin_category_path(category) end column :name column :short_description column :description |product| product.description.truncate(90) end column :subtitle column :created_at column :updated_at actions end show tabs tab 'product' attributes_table row :id row :image image_tag(product.image.url(:medium)) end row :category_id category = category.find(product.category_id) link_to category.name, admin_category_path(category) end row :name row :short_description row :description row :subtitle row :created_at row :updated_at end end tab 'prices' attributes_table row :prices div product.product_currencies.each |product_currency| div "#{currency.find(product_currency.currency_id).name}: #{product_currency.price}" end end end end end end tab 'variants' div 'variants here =)' end end end end form |f| tabs tab 'product' f.inputs f.input :category_id, as: :select, collection: category.all.collect { |category| [category.name, category.id] } f.input :name f.input :short_description f.input :description f.input :subtitle f.input :image, as: :file end end tab 'price' f.inputs f.has_many :product_currencies, allow_destroy: true, heading: false, new_record: 'add new price' |product_currency| product_currency.template.render partial: 'product-price-form', locals: { product_currency: product_currency, product_id: params[:id].to_i } end end end tab 'variants' f.inputs f.has_many :variants, allow_destroy: true, heading: false, new_record: 'add new variant' |variant| variant.template.render partial: 'variant-form', locals: { variant: variant, product_id: params[:id].to_i } end end end tab 'seo' div 'seo inputs here' end end end f.actions end end so, i've installed activeadmin-ajax_filter gem. tried follow documentation, result - nothing. far, understand, have put line of code option activeadmin model: activeadmin-ajax_filter, , in form use this:
f.input :option, as: :ajax_select, data: { url: filter_admin_options_path, search_fields: [:name], static_ransack: { active_eq: true }, ajax_search_fields: [:option_value_id], } but still - nothing. way, partial is:
<% if @product.new_record? %> <% if product.any? %> <% new_product_id = product.order(id: :desc).first.id + 1 %> <% variant.input :product_id, as: :hidden, input_html: { value: new_product_id } %> <% else %> <% variant.input :product_id, as: :hidden, input_html: { value: 1 } %> <% end %> <% else %> <% variant.input :product_id, as: :hidden, input_html: { value: product_id } %> <% end %> <% variant.input :in_stock_id, as: :select, collection: instock.all.collect { |in_stock| [in_stock.name, in_stock.id] } %> <% variant.input :sold_out_id, as: :select, collection: soldout.all.collect { |sold_out| [sold_out.name, sold_out.id] } %> <%# variant.input :option, as: :ajax_select, collection: option.all.collect { |option| [option.name, option.id] }, # data: { # url: filter_admin_options_path, # serarch_fields: [:name], # static_ransack: { active_eq: true }, # ajax_search_fields: [:option_value_id] # } #%> <% variant.input :option_value_id, as: :select, collection: optionvalue.all .collect { |option_value| [option_value.value, option_value.id] } %> <% variant.input :visible %> <% variant.input :orderable %> <% variant.input :image, as: :file %> can help? hope wasn't annoying. in advanced, , don't strict.
Comments
Post a Comment