lucky
lucky copied to clipboard
Add optional_param with enums
This sets up some enums so you can have type safe params
class Tasks::Index
# `allow` will create an enum
param filter, default: All, allow: [All, Completed, Incomplete]
action do
# This will be extra cool/if when they have exhaustiveness checks on enums!
case Filter
when All
tasks = TaskQuery.all
when Completed
tasks = TaskQuery.new.completed
when Incomplete
tasks = TaskQuery.new.incomplete
end
render tasks: tasks
end
end
# You can only use things in the enum when using a route
link "complete", to: Tasks::Index.route(filter: Tasks::Index::Filter::Completed)
This API isn’t finalized so please hold off on working on it if you see this issue