module RouteBound

Implicit model binding for Rails. Include in any ApplicationController instance.

Constants

VERSION

Public Class Methods

included(base) click to toggle source
# File lib/route_bound.rb, line 4
def self.included(base)
  base.before_action :route_bound_find_model
end

Public Instance Methods

route_bound_find_model() click to toggle source
# File lib/route_bound.rb, line 8
def route_bound_find_model
  instance_variable_set("@#{implied_model_name.downcase}", implied_model)
rescue NameError
  Rails.logger.info("RouteBound unable to find the model #{implied_model_name}")
end

Private Instance Methods

implied_model() click to toggle source
# File lib/route_bound.rb, line 20
def implied_model
  Object.const_get(implied_model_name).send(:find, params[:id])
end
implied_model_name() click to toggle source
# File lib/route_bound.rb, line 16
def implied_model_name
  params[:controller].singularize.capitalize
end