module ActionController::Route::Param

Overview

this namespace is used to provide transparent strong parameters

all transparent converters need to match the desired Class name and be prefixed with Convert

i.e. let's take a class like Int32

struct AC::Route::Param::ConvertInt32 < AC::Route::Param::Conversion
  def convert(raw : String)
    raw.to_i
  end
end

now if you would like to provide custom options for a converter you can.

in this case we're allowing for a custom Int32 base, i.e. maybe you expect a hex string

struct AC::Route::Param::ConvertInt32 < AC::Route::Param::Conversion
  def initialize(@base : Int32 = 10)
  end

  def convert(raw : String)
    raw.to_i(@base)
  end
end

# then in your routes
@[AC::Route::GET("/hex_route/:id", config: {id: {base: 16}})]
def other_route_test(id : Int32) : Int32
  id # response will be in base 10
end

Defined in:

action-controller/router/route_params.cr