# Don't understand Paginator/Page or Ruby construct

**URL:** <https://www.ruby-forum.com/t/dont-understand-paginator-page-or-ruby-construct/70658>\
**Category:** Rails\
**Created:** [October 1, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/dont-understand-paginator-page-or-ruby-construct/70658 "2006-10-01T16:32:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [October 1, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/dont-understand-paginator-page-or-ruby-construct/70658/1 "2006-10-01T16:32:49Z")

</div>

Just wasted two hours trying to save the current page in the session.

My first approach was stolen from the scaffolded view:  
session[:page] = @person\_pages.current  
But - as I discovered later - this saves a Page object, not only the  
page number. To save the current page I had to use  
session[:page] = @person\_pages.current.number

Scaffolding generates links like:  
\<%= link\_to ‘Previous page’,  
{ :page =\> @person\_pages.current.previous } if  
@person\_pages.current.previous %\>  
and generates a number (the page number) as action parameter.

Can someone explain shortly why the (working) code generated by  
scaffolding in the view evaluates @person\_pages.current.previous (a  
Page object) to a number whereas @person\_pages.current (also a Page  
object) called in the action returns the Page object ?

Thanks,  
Thomas

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [October 1, 2006, 4:38pm UTC](https://www.ruby-forum.com/t/dont-understand-paginator-page-or-ruby-construct/70658/2 "2006-10-01T16:38:50Z")

</div>

It probably does a to\_s on it which returns a ‘number’.

Vish

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [October 1, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/dont-understand-paginator-page-or-ruby-construct/70658/3 "2006-10-01T16:42:50Z")

</div>

On Oct 1, 2006, at 16:29, Thomas wrote:

> Can someone explain shortly why the (working) code generated by  
> scaffolding in the view evaluates @person\_pages.current.previous (a  
> Page object) to a number whereas @person\_pages.current (also a Page  
> object) called in the action returns the Page object ?

Views default to calling to\_s on objects to get the value to render,  
hence \<%= @person\_pages.current %\> in a view is really the return  
value of @person\_pages.current.to\_s.

–  
Jakob S. - [http://mentalized.net](http://mentalized.net)

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [October 1, 2006, 7:03pm UTC](https://www.ruby-forum.com/t/dont-understand-paginator-page-or-ruby-construct/70658/4 "2006-10-01T19:03:18Z")

</div>

On 10/1/06, Jakob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Views default to calling to\_s on objects to get the value to render,  
> hence \<%= @person\_pages.current %\> in a view is really the return  
> value of @person\_pages.current.to\_s.

Thank you very much.

In my opionion, it’s a bug.

With my limited experience in Rails and Ruby, I have seen the view as  
“the  
thing displaying my instance vars” and the code written in the view as  
“another method of the controller”. Now I discover that something too  
much  
magic happens and the code in the views are interpreted differently, so  
forcing me to remember an unnecessary detail (“remember always - coding  
in  
‘Controller’ or ‘View’ context ?”, “be aware when you copy/paste some  
expressions”).

As the real fix (either remove to\_s from Pages or the magic from the  
view  
interpreter) most likely will break existing code, maybe it would be  
nice  
when at least the scaffolder adds ‘to\_s’ ?

Thomas
