Module: Superglue::Helpers
- Included in:
- Controller
- Defined in:
- lib/superglue/helpers.rb
Instance Method Summary collapse
- #param_to_search_path(param) ⇒ Object
- #redirect_back_with_props_at(opts) ⇒ Object
- #search_path_to_camelized_param(path) ⇒ Object
Instance Method Details
#param_to_search_path(param) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/superglue/helpers.rb', line 17 def param_to_search_path(param) if param param.gsub(/[^\da-zA-Z_=.]+/, "").squeeze(".") .split(".") .map do |part| if /^-?[0-9]+$/.match?(part) part.to_i else part end end end end |
#redirect_back_with_props_at(opts) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/superglue/helpers.rb', line 3 def redirect_back_with_props_at(opts) if request.referrer && params[:props_at] referrer_url = URI.parse(request.referrer) referrer_url.query = Rack::Utils .parse_nested_query(referrer_url.query) .merge({props_at: params[:props_at]}) .to_query redirect_to referrer_url.to_s, opts else redirect_back(opts) end end |
#search_path_to_camelized_param(path) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/superglue/helpers.rb', line 31 def search_path_to_camelized_param(path) path.map do |part| if part.include? "=" key, rest = part.split("=") [key.camelize(:lower), rest].join("=") else part.camelize(:lower) end end.join(".") end |