Hello,
I am very new to RoR and am learning at a fairly good pace, but a
seemingly simple task is leaving me stuck. I have a DB table called
'workers' and fields for 'first_name' and 'last_name' need to be
combined in the 'list' view and shown in order of last name. The code
I have below will render the name as "Last, First". How can I order
the table by the name column when it is a combination of 2 fields?
--thanks
<table class="list" width="90%">
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone Number #1</th>
<th>Phone Number #2</th>
<th>Options</th>
</tr>
<% for worker in @workers %>
<% row_color = cycle("F8F8F8", "ffffff")%>
<tr style="background: #<%= row_color %>;">
<td><%= link_to %Q{ #{worker.last_name},
#{worker.first_name}}, :action => 'show', :id => worker %></td>
<td><%= mail_to worker.email, worker.email, :subject => "This is
an example email", :body => "This is the body of the message." %></
I'm pretty new to RoR, too. But for what it's worth, I think you need
to look at your controller which populates your @workers collection
and add an :order expression, something like:
Nice job. But do you know where there's an example of this where the
app toggles between ASC and DESC when the column-name is clicked?
I got some suggestions about this a few months ago but never got it
working right. I'd like to find an "applet" on the Web or in a book
that demonstrates this.
Thanks for that GREAT article. Of course, it's all JavaScript rather
than Ruby/Rails. But it works nicely and is designed beautifully, so
it'll be a great education for me to translate it to RoR with minimal
JavaScript.