# Will\_paginate links have broken urls

**URL:** <https://www.ruby-forum.com/t/will-paginate-links-have-broken-urls/169755>\
**Category:** Rails\
**Created:** [June 8, 2009, 11:39am UTC](https://www.ruby-forum.com/t/will-paginate-links-have-broken-urls/169755 "2009-06-08T11:39:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [June 8, 2009, 11:39am UTC](https://www.ruby-forum.com/t/will-paginate-links-have-broken-urls/169755/1 "2009-06-08T11:39:26Z")

</div>

hey folks

I have a page that used to have a url in this sort of form

/resources/browse/property\_ids[]=72&property\_ids[]=722

I changed the format to be nicer - using the name of the properties and  
seperating with a +

/resources/browse/72-Violin+722-Pieces

The ‘+’ acts as a join between two property ids effectively, so in the  
controller the last part is split on +, and the above is equivalent to  
the first url.

This all works fine, and gives a nicer url. However, will\_paginate is  
now doing something strange - the paginate links for the page now come  
out like this:

/resources/browse/72-Violin/722-Pieces?page=3

where i’d expect them to be this, ie to just add the param to the end of  
whatever the current page is:

/resources/browse/72-Violin+722-Pieces?page=3

Before/while i dive into the guts of will\_paginate to see what might be  
going wrong, can anyone shed any light?

thanks  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [June 8, 2009, 2:11pm UTC](https://www.ruby-forum.com/t/will-paginate-links-have-broken-urls/169755/2 "2009-06-08T14:11:19Z")

</div>

SOLVED

This was nothing to do with will\_paginate at all - it was down to me  
doing something bad in the controller. It’s maybe a bit of a gotcha.

There was a key in params called :property\_ids, which could point to a  
string or an array. If it’s a string, then i need to split it on the +  
sign and turn it into an array.

The problem was i was doing this by altering the contents of params  
itself, like this:

```
  if params[:property_ids].is_a?(String)
    params[:property_ids] = params[:property_ids].split("+")
  end

```

This was then being passed through to the page, in @template.params,  
which will\_paginate uses, and the change from the string to an array was  
making will\_paginate go wrong, generating an invalid url.

So, the lesson here is ‘don’t alter params, copy the value out into a  
variable and then do the manipulation on that’.

I ended up doing a tour into the guts of will\_paginate, and then all the  
way back out again, just to discover this. doh.
