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 %>
SELECT HELPER ? COLLECTION SELECT?
<%= submit_tag “Show” %>
controller view action
def show
@enquiry = Enquiry.find(params[:id])
end
anyone? I just need a basic dropdown which passes the id of the selected
enquiry.
bingo bob wrote:
<% 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
–
Darrik Mazey
DMT Programming, LLC.
any ideas, does my show action need to change, or the collection select,
OR the params passed from when I move to the show action from the edit ?
Darrick,
That’s great thanks, I tried this before (or something very similar and
it worked)…Here’s the problem though…
That show action works your way from the collection select drop down…
However…
When I do it this it brakes something else (the show action after I’ve
editted a form).
e.g this URL.
http://localhost:3000/enquiries/show/5
I see why it’s broken I just don’t know how to fix it…so it’s like
I’ve got two situations, one from the dropdown and one from a regular
form and I’d like the show action to deal with both?
Hope that makes sense… BTW I love the enhancement in my model which I
did giving first initial then lastname…
Any ideas?
What makes you think your question is more important than everyone
else’s?
On Sep 13, 11:32 pm, bingo bob [email protected]
bingo bob wrote:
When I do it this it brakes something else (the show action after I’ve
editted a form).
e.g this URL.
http://localhost:3000/enquiries/show/5
If you’re using RESTful routes, that url should be:
http://localhost:3000/enquiries/5/show
Not sure how you’re getting to the other. Are you using the url
generator methods? e.g. enquiry_url(@enquiry) and friends?
If you use the url generator methods for all of your links, you
shouldn’t have any problems. Use these as parameters to redirect_to and
link_to.
<%= link_to ‘list’, enquiries_path %>
… or …
redirect_to enquiry_url(@enquiry)
How are you generating the url you listed above?
Cheers,
Darrik