restful routes rename :id

I have this routes

resources :posts, :controller => 'frontend/posts' do
 resources :photos, :controller => 'frontend/posts'

So frontend/posts_controller handles these requests:


Somtimes the :id means the photo id and in some cases the post id. I want that post always uses :post_id . Is it possible to rename :id in :post_id without adding custom(match ...) routes?



You should just write your finders to handle both cases. It's easier than messing around with parameter names:

@post = Post.find(params[:post_id] || params[:id])

That being said, I agree that it's annoying that the :id parameter changes names depending on the depth of the resource call.

The presence of :post_id is what will differentiate between the two routes. Personally, unless I have a compelling reason to depart from convention, I try to avoid it.

Need Your Help


objective-c ios cocoa-touch memory-management uigesturerecognizer

Is there a way to undo requireGestureRecognizerToFail.

C# RegExp Indentation and Line Break

c# regex

I'm trying to insert an indented code inside another indented code, using the first indentation as base for the second.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.