# Get and Set method in Ruby on Rails

**URL:** <https://www.ruby-forum.com/t/get-and-set-method-in-ruby-on-rails/176700>\
**Category:** Rails\
**Created:** [October 5, 2009, 8:33am UTC](https://www.ruby-forum.com/t/get-and-set-method-in-ruby-on-rails/176700 "2009-10-05T08:33:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![venki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@venki](https://www.ruby-forum.com/u/venki)\
**Post date:** [October 5, 2009, 8:33am UTC](https://www.ruby-forum.com/t/get-and-set-method-in-ruby-on-rails/176700/1 "2009-10-05T08:33:26Z")

</div>

Hi,

I working on Ruby on Rails.I using Ajax in that.While using pagination  
in my application first time only I want to give request to Mysql Data  
Base ,If user click second page it should not take from database. Here  
I can use Set and get methods or different method will be there. How  
to implement this?

---

<div class="post-metadata">

**Author:** ![venki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@venki](https://www.ruby-forum.com/u/venki)\
**Post date:** [October 5, 2009, 7:35pm UTC](https://www.ruby-forum.com/t/get-and-set-method-in-ruby-on-rails/176700/2 "2009-10-05T19:35:00Z")

</div>

On Mon, Oct 5, 2009 at 12:42 AM, venki [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I working on Ruby on Rails.I using Ajax in that.While using pagination  
> in my application first time only I want to give request to Mysql Data  
> Base ,If user click second page it should not take from database. Here  
> I can use Set and get methods or different method will be there. How  
> to implement this?

Ruby has attr\_\* for getters and setters:

[http://www.ruby-doc.org/core/classes/Module.html#M001678](http://www.ruby-doc.org/core/classes/Module.html#M001678)

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![venki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@venki](https://www.ruby-forum.com/u/venki)\
**Post date:** [October 5, 2009, 10:16pm UTC](https://www.ruby-forum.com/t/get-and-set-method-in-ruby-on-rails/176700/3 "2009-10-05T22:16:01Z")

</div>

Well, you’re not going to be doing this in Ruby, since HTTP is  
stateless. Since you’re using AJAX, you might as well store your  
entire resultset as JS, and fetch each page from your local  
collection. That said, maybe you should look at Mislav will\_paginate  
([GitHub - mislav/will\_paginate: Pagination library for Rails and other Ruby applications](http://github.com/mislav/will_paginate)). Sure, you’ll hit the DB for  
each page, but it’s simple to implement, it’s well tested and it  
performs reasonably well.

Cheers,  
Tim
