Class: IndexFor::WiceBuilder
- Defined in:
- lib/index_for/builders/wice_builder.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#order ⇒ Object
Returns the value of attribute order.
-
#page ⇒ Object
Returns the value of attribute page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#search ⇒ Object
Returns the value of attribute search.
Attributes inherited from Builder
#html_options, #object, #template
Instance Method Summary collapse
- #attribute(attribute_name, options = {}) ⇒ Object
- #fields_for(attribute_name, options = {}, &block) ⇒ Object
- #per_pages ⇒ Object
- #result ⇒ Object
- #searchable_fields ⇒ Object
- #sortable_fields ⇒ Object
Methods inherited from Builder
#actions, #association, #attributes, #initialize
Constructor Details
This class inherits a constructor from IndexFor::Builder
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
5 6 7 |
# File 'lib/index_for/builders/wice_builder.rb', line 5 def direction @direction end |
#order ⇒ Object
Returns the value of attribute order.
5 6 7 |
# File 'lib/index_for/builders/wice_builder.rb', line 5 def order @order end |
#page ⇒ Object
Returns the value of attribute page.
5 6 7 |
# File 'lib/index_for/builders/wice_builder.rb', line 5 def page @page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
5 6 7 |
# File 'lib/index_for/builders/wice_builder.rb', line 5 def per_page @per_page end |
#search ⇒ Object
Returns the value of attribute search.
5 6 7 |
# File 'lib/index_for/builders/wice_builder.rb', line 5 def search @search end |
Instance Method Details
#attribute(attribute_name, options = {}) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/index_for/builders/wice_builder.rb', line 15 def attribute attribute_name, = {} model_class = [:model] || [:model] || @object sortable_fields << ([:sortable] || "#{model_class.table_name}.#{attribute_name}") searchable_fields << "#{model_class.table_name}.#{attribute_name}" if [:searchable] nil end |
#fields_for(attribute_name, options = {}, &block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/index_for/builders/wice_builder.rb', line 22 def fields_for attribute_name, = {}, &block = @html_options @html_options = block.call self @html_options = nil end |
#per_pages ⇒ Object
46 47 48 49 50 51 |
# File 'lib/index_for/builders/wice_builder.rb', line 46 def per_pages params = template.params.permit! IndexFor.per_pages.each do |per_page| yield per_page, @template.url_for(params.merge(page: nil, per_page: per_page)), per_page == self.per_page end end |
#result ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/index_for/builders/wice_builder.rb', line 30 def result params = @template.params self.per_page = (params[:per_page] || IndexFor.per_page).to_i self.page = (params[:page] || 1).to_i self.order = params[:order] if sortable_fields.include? params[:order] self.direction = params[:direction] || "asc" self.search = params[:search] collection = @object collection = collection.page(page).per(per_page) collection = collection.order("#{order} #{direction.upcase}") if order collection = collection.where(searchable_fields.map{|f|"#{f} LIKE '%#{search}%'"}.join(" OR ")) if search collection end |
#searchable_fields ⇒ Object
11 12 13 |
# File 'lib/index_for/builders/wice_builder.rb', line 11 def searchable_fields @searchable_fields ||= [] end |
#sortable_fields ⇒ Object
7 8 9 |
# File 'lib/index_for/builders/wice_builder.rb', line 7 def sortable_fields @sortable_fields ||= [] end |