Ruby on Rails Tuesday, August 24, 2010

Bob Smith wrote:
>
> I have 2 name fields called name and sname. What I am trying to do is
> show both names in the index page at the beginning of
> the app. They need to be combined as a list which is then put in
> alphabetical order and given to the index page to be displayed with
> edit links for each item.
>
> Bob

controller:

def index
# get ordered households
@households = Household.find(:all, :order => 'sname, name')
end

index view:
<table>
<% @households.each do |hh| %>
<tr>
<td><%= link_to 'Edit Me!', edit_household_path(hh) %></td>
<td><%= link_to 'Old school link', :controller => 'households',
:action => 'edit', :id => hh.id %></td>
<td><%= h(hh.sname)+', '+h(hh.name) %></td>
</tr>
<% end %>
</table>

or if you simply want a list of links:

<table>
<% @households.each do |hh| %>
<tr>
<td><%= link_to h(hh.sname)+', '+h(hh.name),
edit_household_path(hh) %></td>
</tr>
<% end %>
</table>


or something like that...
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment