[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myexperiment-hackers] Route issue with "aliased" models
From: |
Finn Bacall |
Subject: |
[myexperiment-hackers] Route issue with "aliased" models |
Date: |
Fri, 02 Dec 2011 10:34:03 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110921 Thunderbird/3.1.15 |
I've decided to rewrite some code in my datasets branch to take
advantage of Rails 2's ability to automatically infer routes from a
given object (for example 'link_to(@object.name, @object')).
However, it can't figure out what to do with instances of Blob and
Network as, the resources described in the routes file are named "Files"
and "Groups" respectively.
To solve this, rather than having: "resources :files, :controller =>
:blobs..."
you can use: "resources :blobs, :as => :files..."
which would maintain the same functionality/URL paths as the one above,
and Rails would know that its the route for the "Blob" model.
This has the advantage of allowing things that deal with heterogeneous
sets of resources to be able to generate links to resources without
needing switch statements.
The major issue is, all instances of "file_path(@file.id)" etc. would
have to be replaced with "blob_path(@file.id)". As far as I can tell,
there isn't a way to avoid this.
I'd like to hear peoples' thoughts on this.
-Finn
--
Finn Bacall
School of Computer Science
University of Manchester
- [myexperiment-hackers] Route issue with "aliased" models,
Finn Bacall <=