# Comparing data

**URL:** <https://www.ruby-forum.com/t/comparing-data/178633>\
**Category:** Rails\
**Created:** [November 8, 2009, 2:31pm UTC](https://www.ruby-forum.com/t/comparing-data/178633 "2009-11-08T14:31:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [November 8, 2009, 2:31pm UTC](https://www.ruby-forum.com/t/comparing-data/178633/1 "2009-11-08T14:31:10Z")

</div>

Hello,

I’m trying to implement Rails functionality which would allow to compare  
Model records (in my case different plans).

I’m unsure what would be the proper approach towards this with Rails, is  
there any tutorial for doing something like available on internet/book?

Which would be better: to pass the comparing model ids to the compare  
controller by post or by url?

Any tips are highly appreciated.

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [November 8, 2009, 2:43pm UTC](https://www.ruby-forum.com/t/comparing-data/178633/2 "2009-11-08T14:43:19Z")

</div>

2009/11/8 Aljaz F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> controller by post or by url?
> 
> ## Any tips are highly appreciated.

If I understand correctly you have records in the db and wish to  
compare them on demand by the user clicking on a link which goes to a  
compare controller. In this case I would pass the id values as  
parameters of a GET request on the compare controller. It should not  
be a POST as it does not cause the data in the db to be changed. The  
actual compare operation should be a method of the model whose objects  
are being compared of course.

Colin

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [November 8, 2009, 2:51pm UTC](https://www.ruby-forum.com/t/comparing-data/178633/3 "2009-11-08T14:51:04Z")

</div>

How can you pass array of parameters to GET request?

Colin L. wrote:

> 2009/11/8 Aljaz F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > controller by post or by url?
> > 
> > ## Any tips are highly appreciated.
> 
> If I understand correctly you have records in the db and wish to  
> compare them on demand by the user clicking on a link which goes to a  
> compare controller. In this case I would pass the id values as  
> parameters of a GET request on the compare controller. It should not  
> be a POST as it does not cause the data in the db to be changed. The  
> actual compare operation should be a method of the model whose objects  
> are being compared of course.
> 
> Colin

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [November 8, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/comparing-data/178633/4 "2009-11-08T16:34:44Z")

</div>

Colin L. wrote:

> 2009/11/8 Aljaz F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > How can you pass array of parameters to GET request?
> 
> The same as anything else, eg  
> if @my\_array contains [0,1,2]  
> \<%= link\_to ‘Compare’, :controller =\> ‘compare’, :action =\>  
> ‘do\_compare’, :ids =\> @my\_array %\>
> 
> If the values you want to pass come from fields then it just a matter  
> of setting up the fields correctly. Google should be able to sort you  
> out, I always have to look it up.
> 
> If you are only comparing two records then just pass the ids as two  
> params.
> 
> Colin

Would it make more sense to make separate controller for comparations or  
would it be better to place it inside Plans controller?

Thanks again!

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [November 8, 2009, 3:14pm UTC](https://www.ruby-forum.com/t/comparing-data/178633/5 "2009-11-08T15:14:55Z")

</div>

2009/11/8 Aljaz F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> How can you pass array of parameters to GET request?

The same as anything else, eg  
if @my\_array contains [0,1,2]  
\<%= link\_to ‘Compare’, :controller =\> ‘compare’, :action =\>  
‘do\_compare’, :ids =\> @my\_array %\>

If the values you want to pass come from fields then it just a matter  
of setting up the fields correctly. Google should be able to sort you  
out, I always have to look it up.

If you are only comparing two records then just pass the ids as two  
params.

Colin

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [November 8, 2009, 4:50pm UTC](https://www.ruby-forum.com/t/comparing-data/178633/6 "2009-11-08T16:50:19Z")

</div>

2009/11/8 Aljaz F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Would it make more sense to make separate controller for comparations or  
> would it be better to place it inside Plans controller?

Whichever makes more sense for you is the way to go. I think I would  
probably put it in a compare action in the Plans controller.

Colin

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [November 8, 2009, 5:24pm UTC](https://www.ruby-forum.com/t/comparing-data/178633/7 "2009-11-08T17:24:48Z")

</div>

What would be the best way to build the GET request url with the  
specified plan ids (for instance with form where you can use checkboxes  
to set the desired plans)? Would you do it with JS?

---

<div class="post-metadata">

**Author:** ![introvert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c37758/32.png) [@introvert](https://www.ruby-forum.com/u/introvert)\
**Post date:** [November 8, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/comparing-data/178633/8 "2009-11-08T16:55:36Z")

</div>

I would do it with nested routes and map.resource. You would end up  
with a rout that looked like this:

/plans/:plan\_id/compare/:id

If you are comparing more than one at a time then I would do what was  
suggested before and pass an array of IDs as a GET request.

On Nov 8, 8:31 am, Aljaz F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
