# Making display options sort

**URL:** <https://www.ruby-forum.com/t/making-display-options-sort/157260>\
**Category:** Rails\
**Created:** [January 8, 2009, 10:58pm UTC](https://www.ruby-forum.com/t/making-display-options-sort/157260 "2009-01-08T22:58:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanoverton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@ryanoverton](https://www.ruby-forum.com/u/ryanoverton)\
**Post date:** [January 8, 2009, 10:58pm UTC](https://www.ruby-forum.com/t/making-display-options-sort/157260/1 "2009-01-08T22:58:02Z")

</div>

I’m doing some editing on an existing rails app and this view;  
\_tour\_listing.html.erb looks like this:

\<% if @upcoming\_tour\_requests.blank? %\>

No upcoming tour requests.

\<% else %\> \<%= render :partial =\> "tour\_listing", :collection =\> @upcoming\_tour\_requests %\>

| Group Name | Contact Name | Status | Date | Actions |
| --- | --- | --- | --- | --- |

\<% end %\>
### Other Active Tour Requests

Tour requests not scheduled to take place within the next two weeks, but still having a status of initial, received, or confirmed:

\<% if @tour\_requests.blank? %\>

No other active tour requests.

\<% else %\> \<%= render :partial =\> "tour\_listing", :collection =\> @tour\_requests %\>

| Group Name | Contact Name | Status | Date | Actions |
| --- | --- | --- | --- | --- |

\<% end %\>

My question is with the render :partial =\> etc… line. I need to find  
away to sort the data that is getting spit out by a specific field, how  
would I do that?

---

<div class="post-metadata">

**Author:** ![ryanoverton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@ryanoverton](https://www.ruby-forum.com/u/ryanoverton)\
**Post date:** [January 8, 2009, 11:24pm UTC](https://www.ruby-forum.com/t/making-display-options-sort/157260/2 "2009-01-08T23:24:27Z")

</div>

How about making the

 a remote link and have a action that pulls  
the @tour\_requests sorted from the parameter and then update the  
partial div. ?

---

<div class="post-metadata">

**Author:** ![ryanoverton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@ryanoverton](https://www.ruby-forum.com/u/ryanoverton)\
**Post date:** [January 8, 2009, 11:24pm UTC](https://www.ruby-forum.com/t/making-display-options-sort/157260/3 "2009-01-08T23:24:56Z")

</div>

> My question is with the render :partial =\> etc… line. I need to find  
> away to sort the data that is getting spit out by a specific field, how  
> would I do that?

You’ll want to do that when the data is marshalled, not in the view or  
parital code… look into the controller to see how your data is  
retrieved.

Then, the model whose is being displayed should be able to provide the  
data in the desired order…

---

<div class="post-metadata">

**Author:** ![ryanoverton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@ryanoverton](https://www.ruby-forum.com/u/ryanoverton)\
**Post date:** [January 8, 2009, 11:32pm UTC](https://www.ruby-forum.com/t/making-display-options-sort/157260/4 "2009-01-08T23:32:07Z")

</div>

Quoting Ryan O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I’m doing some editing on an existing rails app and this view;  
> \_tour\_listing.html.erb looks like this:  
> [snip]  
> My question is with the render :partial =\> etc… line. I need to find  
> away to sort the data that is getting spit out by a specific field, how  
> would I do that?

Sort it in the controller or model, wherever the find() is. Often:

@upcoming\_tour\_requests = TourRequests.find(:all, :order =\> ‘date’)

Anything SQL accepts can go in the :order value, ‘date DESC’, ‘id’, etc.

Another point, blank? is for strings, empty? is standard Ruby for  
arrays.

HTH,  
Jeffrey
