私はruby on rail 4.2.5とfilterrificとwill_paginate 3.0.6 gemを使用しています。しかし、私は任意のチェックボックスを選択すると、私のjavascriptが壊れていると動作しません。ruby on railでfilterrificとwill_paginateを使用しているときにjavascriptが動作しない
その私のjsファイル
$('.spin span:last-child').click(function(){
inputValue = parseInt($(this).parent().find($('.custom-input')).val());
inputValue += 1
$(this).parent().find($('.custom-input')).val(inputValue);
unitPrice = parseFloat($(this).closest('.product').find('.unit-price span').text().substring(3));
subTotal = parseFloat(inputValue * unitPrice).toFixed(2);
$(this).closest('.product').find('.total-price span').text(subTotal);
});だから、
その私のindex.html.hamlソート私の製品
.flex-container.products.wrapper.no-flex
.flex-container.relative
= form_for_filterrific @filterrific do |f|
.flex-item.sort-items<
Sort for
.select-style
= f.select(:sorted_by, @filterrific.select_options[:sorted_by], id: 'sort-select', include_blank: 'Seleccionar')
.filter-items.panel.panel-body
%h3.no-margin Mostrar por
%h4<
Type
%i.fa.fa-chevron-down>
%i.fa.fa-chevron-up
%ul
- @filterrific.select_options[:with_brand].each do |brand|
%li
= f.check_box :with_brand, { multiple: true, id: "filterrific_#{brand.name}", class: 'custom-checkbox' }, brand.id
= f.label brand.name, class: 'custom-label'
%h4<
Category
%i.fa.fa-chevron-down>
%i.fa.fa-chevron-up
私products_controller.rb
class ProductsController < ApplicationController
def index
@filterrific = initialize_filterrific(
DistributorProduct,
params[:filterrific],
select_options: {
sorted_by: DistributorProduct.options_for_sorted_by,
with_brand: Brand.select(:id, :name),
with_category: Category.select(:id, :name),
with_distributor: Distributor.select(:id, :name),
with_presentation: Presentation.select(:id, :name)
},
persistence_id: false
) || return
@distributor_products = @filterrific.find.page(params[:page]).search_query(params[:category], params[:search]).includes(:product)
@order_item = current_order.order_items.new
@brands = Brand.all
@categories = Category.all
@distributors = Distributor.all
@presentations = Presentation.all
end
end
と私のdistributor_product.rbモデル
class DistributorProduct < ActiveRecord::Base
filterrific(available_filters: [
:sorted_by,
:search_query,
:with_brand,
:with_category,
:with_distributor,
:with_presentation])
self.per_page = 9
belongs_to :distributor
belongs_to :product
has_many :sub_order_items
has_many :order_items
scope :search_query, lambda { |field, query|
return nil if query.blank?
query = "%#{query.downcase}%"
k, value = field.split('-')
key = k == 'sc' ? 'sub_categories' : 'categories'
joins(product: { categories: :sub_categories }).where(key => { id: value.to_s }).where('LOWER(products.name) LIKE ?', query).distinct
}
scope :sorted_by, lambda { |sort_option|
direction = (sort_option =~ /desc$/) ? 'desc' : 'asc'
case sort_option.to_s
when /^created_at_/
order("distributor_products.created_at #{direction}")
when /^name_/
order("distributor_products.name #{direction}")
when /^unit_price_/
order("distributor_products.unit_price #{direction}")
else
raise(ArgumentError, "Invalid sort option: #{sort_option.inspect}")
end
}
scope :with_brand, lambda { |brand_id|
return nil if brand_id.uniq == ['0']
joins(:product).where(products: { brand_id: brand_id })
}
scope :with_category, lambda { |category_id|
return nil if category_id.uniq == ['0']
joins(product: :categories).where(categories: { id: category_id })
}
scope :with_distributor, lambda { |distributor_id|
return nil if distributor_id.uniq == ['0']
where(distributor_id: distributor_id)
}
scope :with_presentation, lambda { |presentation_id|
return nil if presentation_id.uniq == ['0']
joins(:product).where(products: { presentation_id: presentation_id })
}
def self.options_for_sorted_by
[
['Nombre (a-z)', 'name_asc'],
['Nombre (z-a)', 'name_desc'],
['Precio (menor a mayor)', 'unit_price_asc'],
['Precio (mayor a menor)', 'unit_price_desc']
]
end
def image_url
"https://s3-sa-east-1.amazonaws.com/riqraops/catalogo/#{image}.png"
end
end
、私はありません持っています私のチェックボックスが選択されているときに私のjsが動作していないアイデア、私はそのページをリロードする必要があります:/、thx 反応。