bluescreen303-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-21 15:17 UTC
multiple ids on restful action
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
you could use *ids in your routing which would allow for an array of ids using a non encoded / -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bluescreen303-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-21 22:50 UTC
Re: multiple ids on restful action
Cool, And how can I do this on RESTful routes? map.resources :posts .... Will it work too if I use nesting? /posts/13/comments Greetings, Mathijs On 21 jan, 16:41, Keynan Pratt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> you could use *ids in your routing which would allow for an array of ids > using a non encoded / > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---