lucky icon indicating copy to clipboard operation
lucky copied to clipboard

Add optional_param with enums

Open paulcsmith opened this issue 7 years ago • 1 comments

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)

paulcsmith avatar Sep 02 '17 02:09 paulcsmith

This API isn’t finalized so please hold off on working on it if you see this issue

paulcsmith avatar Nov 02 '17 21:11 paulcsmith