Module: Serve::ParamHelpers

Included in:
ViewHelpers
Defined in:
lib/serve/view_helpers.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) boolean_param(key, default = false)

Extract the value for a bool param. Handy for rendering templates in different states.



103
104
105
106
107
108
109
110
111
112
# File 'lib/serve/view_helpers.rb', line 103

def boolean_param(key, default = false)
  key = key.to_s.intern
  value = params[key]
  return default if value.blank?
  case value.strip.downcase
    when 'true', '1'  then true
    when 'false', '0' then false
    else raise 'Invalid value'
  end
end

- (Object) params

Key based access to query parameters. Keys can be strings or symbols.



97
98
99
# File 'lib/serve/view_helpers.rb', line 97

def params
  @params ||= HashWithIndifferentAccess.new(request.query)
end