myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [myexperiment-hackers] Route issue with "aliased" models


From: Finn Bacall
Subject: Re: [myexperiment-hackers] Route issue with "aliased" models
Date: Wed, 07 Dec 2011 16:01:07 +0000
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110921 Thunderbird/3.1.15

This is now done, and ready to go into trunk whenever, just let me know. I also discovered and fixed a bug that is present on the live site at the moment, wherein a stack error occurs if you try and "favourite" a file.

-Finn

On 02/12/11 10:34, Finn Bacall wrote:
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
http://www.myexperiment.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]