Module: Serve::ParamHelpers

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

Instance Method Summary collapse

Instance Method Details

#boolean_param(key, default = false) ⇒ Object

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



106
107
108
109
110
111
112
113
114
115
# File 'lib/serve/view_helpers.rb', line 106

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

#paramsObject

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



100
101
102
# File 'lib/serve/view_helpers.rb', line 100

def params
  @params ||= request.params
end