Module: LitePage::ClassMethods
- Defined in:
- lib/lite_page.rb
Instance Method Summary collapse
-
#page_url(url) ⇒ Symbol
Defines an instance method ‘page_url` which returns the url passed to this method and takes optional query parameters that will be appended to the url if given.
Instance Method Details
#page_url(url) ⇒ Symbol
Defines an instance method ‘page_url` which returns the url passed to this method and takes optional query parameters that will be appended to the url if given.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lite_page.rb', line 29 def page_url(url) define_method(:page_url) do |query_params = {}| uri = URI(url) existing_params = URI.decode_www_form(uri.query || '') new_params = query_params.to_a unless existing_params.empty? && new_params.empty? combined_params = existing_params.push(*new_params) uri.query = URI.encode_www_form(combined_params) end uri.to_s end end |