0
votes

I'm trying to link to the previous page (if available) and the next page (if available). The links show up in the right circumstances, but I cannot get them to link to the proper URL.

I've tried a number of methods to this approach:

<%= link_to 'Prev', url_for(params), class: 'ladder-nav-button pull-left' if has_prev_page? %>
<%= link_to 'Next', ladders_path(params), class: 'ladder-nav-button pull-right' if has_next_page? %>

In addition to things like hardcoding the values:

<%= link_to 'Prev', url_for(region: 'all', page: 1), class: 'ladder-nav-button pull-left' if has_prev_page? %>

I always end up with a link to /ladders, and not /ladders/all/1 or something like that.

The params are there. I can print them out on the page, but the links fail. Here is the relevant route (from rake routes):

ladders GET /ladders(/:region(/:page))(.:format) ladders#show {:page=>1, :region=>"all"}

The region and page are optional, but default to 'all' and 1 if not specified.

Where have I tripped myself up at? Is there some "gotcha" with optional params?

1

1 Answers

1
votes

You're using url_for -- why don't you use the path helper?

<%= link_to ladders_path(region: params[:region], page: params[:page]) %>