bingo bob wrote:
Anyone mind helping with he following, whatever I do I can't get it to
work quite right, I want the selection dropdown to show a list of
enquiries maybe by Enquiry.firstname and when selected the show action
to display the enquiry, I know this should be mega easy but I can't get
it to work with colleciton select.
controller index action
------------------
def index
@enquiries = Enquiry.find(:all, :order => 'created_at ASC')
end
view
---
<% form_tag :controller => 'enquiries', :action => 'show', :id =>
@enquiry do %>
<% form_tag { :controller => 'enquiries', :action => 'show' } %>
<%= collection_select :enquiry, :id, @enquiries, :id, :firstname %>
<%= submit_tag "Show" %>
controller view action
----------------
def show
@enquiry = Enquiry.find(params[:enquiry][:id]
end
Try that.
Hope it helps. NOTE: I didn't test it, but I'm pretty sure it's right, which means you may have to tweak it.
Also of note, if you want something different to show up in the select, you can add a method to your model that returns the proper text and substitute that for :firstname in your collection select.
i.e.
class Enquiry
def last_comma_first
self.lastname.to_s + ', ' + self.firstname.to_s
end
end
<%= collection_select :enquiry, :id, @enquiries, :id, :last_comma_first %>
Cheers,
Darrik