Forum: Ruby on Rails Making display options sort

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ryan O. (Guest)
on 2009-01-08 23:58
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? %>
<p>No upcoming tour requests.</p>
<% else %>
<table>
<tr>
  <th>Group Name</th>
  <th>Contact Name</th>
  <th>Status</th>
  <th>Date</th>
  <th>Actions</th>
</tr>
<%= render :partial => "tour_listing", :collection =>
@upcoming_tour_requests %>
</table>
<% end %>
<h3>Other Active Tour Requests</h3>
<p>Tour requests not scheduled to take place within the next two weeks,
but still having a status of initial, received, or confirmed:</p>
<% if @tour_requests.blank? %>
<p>No other active tour requests.</p>
<% else %>
<table>
<tr>
  <th>Group Name</th>
  <th>Contact Name</th>
  <th>Status</th>
  <th>Date</th>
  <th>Actions</th>
</tr>
<%= render :partial => "tour_listing", :collection => @tour_requests %>
</table>
<% 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?
Freddy A. (Guest)
on 2009-01-09 00:24
(Received via mailing list)
How about making the <th> a remote link and have a action that pulls
the @tour_requests sorted from the parameter and then update the
partial div. ?
Ar C. (Guest)
on 2009-01-09 00:24
> 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...
Jeffrey L. Taylor (Guest)
on 2009-01-09 00:32
(Received via mailing list)
Quoting Ryan O. <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
This topic is locked and can not be replied to.