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)
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)
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. It should be (using your routes above)
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.id
it 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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.