Routes are cool. I was especially pleased when I found out that link_to and the like use them backwards to form the URLs I intend. I just thought I''d mention that. But anyway, I am having trouble with one of my routes, or more specifically, the variable in my route. I have this line in routes.rb: map.connect ''news/:page'', :controller => ''news'' In my news_controller.rb file I have this, which is basically what was there from when I generated the scaffolding: @news_item_pages, @news_items = paginate :news_item, :per_page => 2, :order_by => ''postdate DESC'' In the view, I have the following line to generate the "Next page" link: <% if @news_item_pages.current.next %> <%= link_to "Next page", :page => @news_item_pages.current.next %> <% end %> Now, when I visit the page with the URL /news?page=2 everything works swell and the "Next page" links shows up properly. When I visit the page with the URL /news/2 things mess up. I get the following error, at the link_to line: undefined method `paginator'' for "2":String The "2":String part changes depending on whether I go to /news/3 or /news/17. I do not understand why I get this problem. What do I do? Sincerely, Tom Reinhart tom-V0YqjHVuocLQT0dZR+AlfA@public.gmane.org http://www.AllTom.com/
Hey, Railers. I did not have any luck last time I posted this message here, but I really have no idea where else to ask. I have asked a few times about this issue in the IRC channel, and read a lot of the documentation, but I still feel that I am missing something obvious. My personal belief is that it has something to do with scope, but I cannot be sure. Here is the original e-mail: On 4/21/05, Tom Reinhart <alltom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am having trouble with one of my routes, or more specifically, the > variable in my route. I have this line in routes.rb: > > map.connect ''news/:page'', :controller => ''news'' > > In my news_controller.rb file I have this, which is basically what was > there from when I generated the scaffolding: > > @news_item_pages, @news_items = paginate :news_item, :per_page => > 2, :order_by => ''postdate DESC'' > > In the view, I have the following line to generate the "Next page" > link: > > <% if @news_item_pages.current.next %> > <%= link_to "Next page", :page => @news_item_pages.current.next %> > <% end %> > > Now, when I visit the page with the URL /news?page=2 everything works > swell and the "Next page" links shows up with the correct URL and no > error. When I visit the page with the URL /news/2 things mess up. I > get the following error, at the link_to line: > > undefined method `paginator'' for "2":String > > The "2":String part changes depending on whether I go to /news/3 or > /news/17. I do not understand why I get this problem. What do I do?Sincerely, Tom Reinhart tom-V0YqjHVuocLQT0dZR+AlfA@public.gmane.org http://AllTom.com/
On 4/26/05, Tom Reinhart <alltom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey, Railers. > > I did not have any luck last time I posted this message here, but I > really have no idea where else to ask. I have asked a few times about > this issue in the IRC channel, and read a lot of the documentation, but > I still feel that I am missing something obvious. My personal belief is > that it has something to do with scope, but I cannot be sure. > > Here is the original e-mail: > > On 4/21/05, Tom Reinhart <alltom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am having trouble with one of my routes, or more specifically, the > > variable in my route. I have this line in routes.rb: > > > > map.connect ''news/:page'', :controller => ''news'' > > > > In my news_controller.rb file I have this, which is basically what was > > there from when I generated the scaffolding: > > > > @news_item_pages, @news_items = paginate :news_item, :per_page => > > 2, :order_by => ''postdate DESC'' > > > > In the view, I have the following line to generate the "Next page" > > link: > > > > <% if @news_item_pages.current.next %> > > <%= link_to "Next page", :page => @news_item_pages.current.next %> > > <% end %> > > > > Now, when I visit the page with the URL /news?page=2 everything works > > swell and the "Next page" links shows up with the correct URL and no > > error. When I visit the page with the URL /news/2 things mess up. I > > get the following error, at the link_to line: > > > > undefined method `paginator'' for "2":String > > > > The "2":String part changes depending on whether I go to /news/3 or > > /news/17. I do not understand why I get this problem. What do I do?I made a patch for that bug: http://dev.rubyonrails.com/ticket/1184 Basically, the Pagination_links helper sends a paginator object to the link_to function. This normally works fine because it converts the paginator to a string when forming the URL (action?page=2). However, when it''s in a route, it does some comparison between the Paginator and the default value of that path parameter, which causes that error that you get. My patch forces it to send a string. I also added a :link_prefix option to pagination_links so I could get sweet flickr-style URLs (action/page2). Let me know if it works out. -- rick http://techno-weenie.net