Friendly Routes
Friendly Routes creates DSL for creating rails routes with human friendly URLs
Usage
How to use my plugin.
Installation
Add this line to your application's Gemfile:
gem 'friendly_routes'
And then execute:
$ bundle
Or install it yourself as:
$ gem install friendly_routes
Examples
Routes.rb example
free = FriendlyRoutes::Params::BooleanParams.new(:free, true: :free, false: :paid)
category = FriendlyRoutes::Params::CollectionParams.new(:category_id, Category, :title)
dummies_route = FriendlyRoutes::Route.new([free, category], controller: :dummies, action: :index)
friendly_url_for dummies_route, :get
second_dummies_route = FriendlyRoutes::Route.new([free, 'categories', category], controller: :dummies, action: :index)
friendly_url_for dummies_route, :get, '/'
friendly_url_for dummies_route, :get, '/hello/'
Controller example
class DummiesController < ApplicationController
before_action :parse_friendly_routes, only: [:index]
def index
end
end
Request result example
Categories:
<Category id: 1, title: "lorem">
<Category id: 2, title: "ipsum">
GET "/free/lorem" - { free: true, category_id: 1}
GET "/free/ipsum" - { free: true, category_id: 2}
GET "/paid/lorem" - { free: false, category_id: 1}
GET "/paid/ipsum" - { free: false, category_id: 2}
Contributing
Feel free to contribute into this repository by creating pull requests.
License
The gem is available as open source under the terms of the MIT License.