Project

autolink

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
By setting a default lineage in each model, and using these monkeypatches to Rails, the url helpers are able to generate complex urls from a single ActiveRecord::Base object. Works in 2.3.8, probably other 2.3 railses.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

autolink¶ ↑

Autolink is a small set of monkeypatches to make linking to objects in deeply-namespaced url schemas completely painless. Say you have object @d, which is almost always referred to as /a/b/@d.b.id/c/@d.c.id/d/@d.id. This plugin lets you specify that default in @d’s model, then simply pass @d to rails’ link helpers. So ‘path_for @d` now returns ’/a/1/b/2/c/3/d/4’.

Installation¶ ↑

Autolink only works in Rails 2.3, and has only been tested on 2.3.8. Add it as a gem in config/environment.rb:

config.gem 'autolink'

Then add this to your ‘spec/spec_helper.rb’, under the line that requires ‘spec/rails’:

require 'autolink/rspec'

Now add this to any models that you want to autolink:

def default_lineage
  [:path, :to, :model, parent, self]
end

This default lineage works exactly like ActionController’s PolymorphicRouting lineage (since that’s what it is…).

I make no guarantees that this will work for you.