Pablo Fernandez
Pablo Fernandez

Reputation: 287860

Singular-named routes in Ruby on Rails

I have a fair amount of singleton routes in a Ruby on Rails app, for example:

resource :sessions, :only => [:new, :create, :destroy]
resource :avatars, :only => [:edit, :update]

but the resources themselves are named using the plural form (avatars instead of avatar). I remember reading that this is the way I should do it (somewhere in Rails' documentation) but it always bothered me: I'd rather type edit_avatar_path rather than edit_avatarS_path. Not that it looks ugly (it does), but I tend to forget the plural and get errors.

Now I'm reading the book The Rails 3 Way and in there it explains singular or singleton resources and just shows this code:

resource :profile

and shows the methods profile_path and edit_profile_path without giving any further explanation whether using the singular name would cause any trouble or not.

Can anybody enlighten me in whether there's any potential issues by using the singular name? Any advantages to using the plural?

Upvotes: 2

Views: 855

Answers (1)

Andrew Marshall
Andrew Marshall

Reputation: 97004

I'm fairly certain using the singular name for singular resources is correct. The Rails Routing Guides appears to confirm this, as does the Rails API documentation for resource.

Upvotes: 2

Related Questions