0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Implicit model binding for Ruby on Rails, based on Laravel's implicit model binding.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 5.0.0.1, ~> 5.0.0
 Project Readme

RouteBound

Rails needs some more magic, right? RouteBound is implicit model binding for Ruby on Rails. RouteBound will use a route to try and load a resource for you.

This gem is still very young. It was inspired by Laravel's implicit model binding.

Usage

Implicit model binding will try to load the requested resource for you. In the following example:

  # config/routes.rb
  get 'products/:id', to: 'products#show'
  # app/controllers/products_controller.rb
  class ProductsController < ApplicationController
    include RouteBound

    def show
    end
  end

If you go to /products/1, you will have access to @product without having to explicitly call Product.find(params[:id]). It's already been done for you.

If it can't find the resource, it will silently continue on as normal and will log out to the Rails logger.

Caveats

These are hopefully just temporary.

  • It doesn't currently work with nested resources
  • It doesn't currently allow you to override the query to load the resource

Installation

Add this line to your application's Gemfile:

gem 'route_bound'

And then execute:

$ bundle

Or install it yourself as:

$ gem install route_bound

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.