Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Customizable parameter name in routing. #7860

Closed
NickolasVashchenko opened this Issue · 4 comments

4 participants

@NickolasVashchenko

There is a function "resources" in the class "SingletonResource" that provides 7 routes for an indicated resource, like this:
GET /photos
GET /photos/:id
etc.

Also, there are some gems(as "friendly_id") that give a possibility to store an arbitrary string in :id parameter, what helps to have frendlier links like /photos/big-ben.

But for several reasons this approach makes me feel odd. The fact that in the :id is stored, for example, a name of a model is not quite elegant. And also it leads to such code in controller:

@photo = Photo.find_by_name(params[:id])

Which can be hardy called beautiful. "params[:name]" should fit much better. To avoid this, the gem mentioned above redefines the "find" method in choosen model, but I do not like it too. It can easily provoke gem conflicts, because there is a lot of gems that do it too. E.g., commonly a gem which adds "soft delete" also redefines this method that makes impossible to use them together or can break functionality somehow later.

So, my suggestion is to add a :param_name option to "resources" method so we can have the behavior like this:

resources :photos, :param_name => 'name'

GET /photos/:name

Could it be useful if I add such feature? In addition, there is a whole bunch of questions on stackoveflow with the same desire.

@jherdman

Hi friend. New features such as this are to be discussed on Rails Core mailing list.

@frodsan

@jherdman is right. It's a feature request. It will be better if you get feedback from the Rails Core mailing list. /cc @steveklabnik

@guilleiguaran

Closing here, please ask about it in Mailing list or send a pull request to Journey (the rails router), if people like this probably someone (maybe Aaron Patterson?) can help you implementing it on Journey

@NickolasVashchenko

Ok, thank you, I'll do it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.