Hello out there! I am developing an app that includes a simple forum system, and am using a nested resource there: resources :forums do resources :topics end So I get URLs like /forums/3/topics/2. Now I, for sure, also got a Post model, controller, etc., and I want this controller to redirect to the topic which was posted to, which will work fine with: redirect_to [@topic.forum, @topic] But I want to pass a params[:page] variable to use with the will_paginate gem, so it redirects to the right page of the new post, not just to the first page of the topic as of default. (I wrote a small helper method there to find out the right page for a post) So I tried this: redirect_to [@topic.forum, @topic], :page => find_topic_page(@post) And I neither get a ?page=1 GET request in the URL, nor does it show up in my <%= debug(params) %> stuff. It seems to get lost somewhere in between. So my question would be: How can I redirect to a nested resource''s path and pass a page params variable? -- Thanks in advance! Simon -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Simon Welker wrote in post #1019149:> Hello out there! > I am developing an app that includes a simple forum system, and am > using a nested resource there: > > resources :forums do > resources :topics > end > > So I get URLs like /forums/3/topics/2. Now I, for sure, also got a > Post model, controller, etc., and I want this controller to redirect > to the topic which was posted to, which will work fine with: > > redirect_to [@topic.forum, @topic] > > But I want to pass a params[:page] variable to use with the > will_paginate gem, so it redirects to the right page of the new post, > not just to the first page of the topic as of default. (I wrote a > small helper method there to find out the right page for a post) > > So I tried this: > > redirect_to [@topic.forum, @topic], :page => find_topic_page(@post) >How about: redirect_to( a_named_route(@topic.forum, @topic), { :page => find_topic_page(@post) } ) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim Ruther Nill
2011-Aug-30 15:38 UTC
Re: Re: redirect_to with params for a nested resource?
On Tue, Aug 30, 2011 at 10:29 PM, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Simon Welker wrote in post #1019149: > > Hello out there! > > I am developing an app that includes a simple forum system, and am > > using a nested resource there: > > > > resources :forums do > > resources :topics > > end > > > > So I get URLs like /forums/3/topics/2. Now I, for sure, also got a > > Post model, controller, etc., and I want this controller to redirect > > to the topic which was posted to, which will work fine with: > > > > redirect_to [@topic.forum, @topic] > > > > But I want to pass a params[:page] variable to use with the > > will_paginate gem, so it redirects to the right page of the new post, > > not just to the first page of the topic as of default. (I wrote a > > small helper method there to find out the right page for a post) > > > > So I tried this: > > > > redirect_to [@topic.forum, @topic], :page => find_topic_page(@post) > > > > > How about: > > redirect_to( a_named_route(@topic.forum, @topic), > { :page => find_topic_page(@post) } > ) > >As 7stud pointed out, you might want to resort to using named_routes. But I think 7stud''s syntax is a bit wrong. It should be (using your routes above) redirect_to forum_topic_path(@topic.forum, @topic, :page => find_topic_page(@post))> -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim ruther Nill wrote in post #1019226:> On Tue, Aug 30, 2011 at 10:29 PM, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> > Post model, controller, etc., and I want this controller to redirect >> > >> > As 7stud pointed out, you might want to resort to using named_routes. > But I > think 7stud''s syntax > is a bit wrong. >Whoops. You''re right. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks so far guys. Will try this. Currently I''m using a very raw string concatenation which just appends the page - and the id.> forum_topic_path(@topic.forum, @topic) + "?page=" + find_topic_page(@post) + "#post-" + @post.idit is. So well, I''d be glad if I could replace it with the nice and shiny version.. But how to append the # anchor thingy then, is there some option for that? Thanks, as said :) On 31 Aug., 04:52, 7stud -- <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Jim ruther Nill wrote in post #1019226: > > > On Tue, Aug 30, 2011 at 10:29 PM, 7stud -- <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > >> > Post model, controller, etc., and I want this controller to redirect > > > As 7stud pointed out, you might want to resort to using named_routes. > > But I > > think 7stud''s syntax > > is a bit wrong. > > Whoops. You''re right. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.