Hi,
I know this question has come up before, but I couldn't find
a
satisfying answer.
Maybe I didn't look well enough, so any pointers to old
messages
regarding this subject would be welcome too.
I need some way to pass multiple ids to a resource.
Something like /posts/13,14
If I do this I have to manually split the id on
","s in the action,
and use
post_path([post1, post2].map {|x| x.id}.join(','))
in my views, which I think is not very nice.
If I use post_path([post1, post2]) rails uses to_param on
the array
which leads to the string "13/14" which is
url-encoded to "13%2F14"
but the browser just shows a / in the next screen.
This is nice, since now the controller can split on
"/" and I don't
need to do any string-manipulation in my views.
Only, if a user wants to enter the url by himself
(/posts/13/14) I
will get a routing error because now the / isn't
url-encoded. I can't
expect users to type %2F instead, which just looks ugly.
Now I could override Array's to_param method, but I'm sure
there is a
reason for the default behavior.
So what is the preferred way to solve this? any transparent
way to
handle this?
I mean ActiveRecord handles Post.find(13,14) just fine,
Post.find([13,14]) also.
Is there a way to make ActionController's routing
automatically give
params[:id] back as an array if it detects some pattern?
(something
like from_param maybe?)
Thanks for any help.
Mathijs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
|