List Info

Thread: multiple ids on restful action




multiple ids on restful action
user name
2008-01-21 09:17:40
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: multiple ids on restful action
country flaguser name
Germany
2008-01-21 09:41:03
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: multiple ids on restful action
user name
2008-01-21 16:50:29
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...andreas-s.net>
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )