https://github.com/coreyward/only
https://github.com/coreyward/only
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/coreyward/only
- Owner: coreyward
- License: mit
- Created: 2018-08-27T15:16:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-27T15:55:20.000Z (over 6 years ago)
- Last Synced: 2024-12-31T10:33:25.978Z (4 months ago)
- Language: Ruby
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Only Documentation
Only is a lightweight route definition helper that supplants Rails' built-in route constraints. The single mode of operation is to validate that a condition is true — specifically, that a parameter is included in a provided collection.
This makes it easy to use your models and other objects to create flexible routes that don't allow junk parameters to reach your controllers, reducing potential attack vectors and improving the error responses returned to visitors.
### Example
```ruby
# config/routes.rbOnly.allow category: Category.all.map { |c| c.name.downcase }, prefix: :valid, suffix: :for_post
Rails.application.routes.draw do
only :valid_categories_for_post do
get '/:category/posts' => 'posts#index'
end
end
```