# Form and pagination question

**URL:** <https://www.ruby-forum.com/t/form-and-pagination-question/99773>\
**Category:** Rails\
**Created:** [July 25, 2006, 12:57pm UTC](https://www.ruby-forum.com/t/form-and-pagination-question/99773 "2006-07-25T12:57:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erwann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@Erwann](https://www.ruby-forum.com/u/Erwann)\
**Post date:** [July 25, 2006, 12:57pm UTC](https://www.ruby-forum.com/t/form-and-pagination-question/99773/1 "2006-07-25T12:57:43Z")

</div>

Hello,

How do I get params from a form to use with a paginator?

debug(params) shows this  
city: !map:HashWithIndifferentAccess  
id: “1”

but in my controller, when I try to use  
@hotel\_pages = Paginator.new self, Hotel.count(:conditions =\>  
“hotels.city\_id = params[:city][:id]”), 3, @params[‘page’]

it doesn’t work. I suppose it’s a simple syntax error but have no idea  
to fix it.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Erwann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@Erwann](https://www.ruby-forum.com/u/Erwann)\
**Post date:** [July 26, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/form-and-pagination-question/99773/2 "2006-07-26T14:46:20Z")

</div>

> but in my controller, when I try to use  
> @hotel\_pages = Paginator.new self, Hotel.count(:conditions =\>  
> “hotels.city\_id = params[:city][:id]”), 3, @params[‘page’]
> 
> it doesn’t work. I suppose it’s a simple syntax error but have no idea  
> to fix it.

Nobody?

---

<div class="post-metadata">

**Author:** ![Erwann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@Erwann](https://www.ruby-forum.com/u/Erwann)\
**Post date:** [July 26, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/form-and-pagination-question/99773/3 "2006-07-26T14:46:40Z")

</div>

> but in my controller, when I try to use  
> @hotel\_pages = Paginator.new self, Hotel.count(:conditions =\>  
> “hotels.city\_id = params[:city][:id]”), 3, @params[‘page’]

Nobody?

---

<div class="post-metadata">

**Author:** ![Erwann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@Erwann](https://www.ruby-forum.com/u/Erwann)\
**Post date:** [July 27, 2006, 11:45am UTC](https://www.ruby-forum.com/t/form-and-pagination-question/99773/4 "2006-07-27T11:45:31Z")

</div>

> @hotel\_pages, @hotels = paginate(:hotels, :conditions =\>  
> [“hotels.city\_id = ?”, params[:city][:id]], :per\_page =\> 3, :page =\>  
> @params[‘page’])
> 
> Try something like that.

Thanks Dr Nic, I replaced :page =\> @params[‘page’] by :parameter =\>  
‘page’ and it works but only for the first page, then I have an error  
You might have expected an instance of Array.  
The error occured while evaluating nil.[]

Any idea?

---

<div class="post-metadata">

**Author:** ![Erwann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@Erwann](https://www.ruby-forum.com/u/Erwann)\
**Post date:** [July 26, 2006, 3:18pm UTC](https://www.ruby-forum.com/t/form-and-pagination-question/99773/5 "2006-07-26T15:18:16Z")

</div>

> @hotel\_pages = Paginator.new self, Hotel.count(:conditions =\>  
> “hotels.city\_id = params[:city][:id]”), 3, @params[‘page’]

@hotel\_pages, @hotels = paginate(:hotels, :conditions =\>  
[“hotels.city\_id = ?”, params[:city][:id]], :per\_page =\> 3, :page =\>  
@params[‘page’])

Try something like that.

---

<div class="post-metadata">

**Author:** ![Erwann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@Erwann](https://www.ruby-forum.com/u/Erwann)\
**Post date:** [July 27, 2006, 11:49am UTC](https://www.ruby-forum.com/t/form-and-pagination-question/99773/6 "2006-07-27T11:49:32Z")

</div>

> Thanks Dr Nic, I replaced :page =\> @params[‘page’] by :parameter =\>  
> ‘page’ and it works but only for the first page, then I have an error  
> You might have expected an instance of Array.  
> The error occured while evaluating nil.[]

Try :parameter =\> params[:page]

---

<div class="post-metadata">

**Author:** ![Erwann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@Erwann](https://www.ruby-forum.com/u/Erwann)\
**Post date:** [July 27, 2006, 1:26pm UTC](https://www.ruby-forum.com/t/form-and-pagination-question/99773/7 "2006-07-27T13:26:26Z")

</div>

> Try :parameter =\> params[:page]

In fact, I think it’s more a hash problem in the link previous / next.

I found that in the archives:

“To get a hash through in an url like that you need to serialize it  
and deserialize it. Something like this:”

#in your application controller somewhere:

require ‘base64’  
def construct\_for\_link(object)  
Base64.encode64(Marshal.dump(object))  
end  
helper\_method : construct\_for\_link

def deconstruct\_from\_link(object)  
Marshal.load(Base64.decode64(object))  
end  
helper\_method :deconstruct\_from\_link

# then in your view

\<%= link\_to(‘next’, {:params =\> params.merge(‘answer’ =\>  
construct\_for\_link(@answer),  
‘page’ =\> object\_pages.current.previous,)}) + ’ ’ if  
object\_pages.current.previous %\>

# in controller

answer = deconstruct\_from\_link(params[:answer])

So the question is: is it the only way to add an hash in a link?
