Class: TableMe::UrlBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/table_me/url_builder.rb

Overview

This class builds the url needed for the tables based on the table options. Some options are filtered out to make the url as short as possible.

Class Method Summary collapse

Class Method Details

.filter_options(options) ⇒ Object

Filter out all options except name page search and order We need to dup the objects so we don’t alter the options object through out the table_me module



22
23
24
25
26
27
28
29
# File 'lib/table_me/url_builder.rb', line 22

def filter_options options
  other_tables = options[:other_tables].dup || []
  temp_options = options.dup
  temp_options.keep_if do |k,v|
    ['name','page','search','order'].include? k.to_s
  end
  other_tables << temp_options
end

.url_for(options, additional_options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/table_me/url_builder.rb', line 9

def url_for options, additional_options = {}
  table_options = options.merge additional_options

  url = []
  filter_options(table_options).each do |option|
    url <<  {"tm_#{option[:name]}".to_sym => option }.to_param
  end
    "?#{url.join('&')}"
end