0.0
No commit activity in last 3 years
No release in over 3 years
Friendly routes creates DSL for creating rails routes with human friendly URLs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 5.0.0.1, ~> 5.0.0

Runtime

>= 0
 Project Readme

Friendly Routes

Friendly Routes creates DSL for creating rails routes with human friendly URLs

Gem Version Code Climate Build Status

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

# config/routes.rb
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 # '/:free/:category'

second_dummies_route = FriendlyRoutes::Route.new([free, 'categories', category], controller: :dummies, action: :index)

friendly_url_for dummies_route, :get, '/' # '/:free/categories/:category'
friendly_url_for dummies_route, :get, '/hello/' # '/hello/:free/categories/:category'

Controller example

# app/controllers/dummies_controller.rb
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.