# Basic select drop down returning the right params

**URL:** <https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481>\
**Category:** Rails\
**Created:** [September 13, 2008, 10:22am UTC](https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481 "2008-09-13T10:22:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 13, 2008, 10:22am UTC](https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481/1 "2008-09-13T10:22:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 13, 2008, 11:33am UTC](https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481/2 "2008-09-13T11:33:02Z")

</div>

anyone? I just need a basic dropdown which passes the id of the selected  
enquiry.

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 13, 2008, 11:41am UTC](https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481/3 "2008-09-13T11:41:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 13, 2008, 1:01pm UTC](https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481/4 "2008-09-13T13:01:42Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 14, 2008, 5:32am UTC](https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481/5 "2008-09-14T05:32:02Z")

</div>

bump…

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 13, 2008, 12:30pm UTC](https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481/6 "2008-09-13T12:30:53Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 14, 2008, 7:31pm UTC](https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481/7 "2008-09-14T19:31:45Z")

</div>

What makes you think your question is more important than everyone  
else’s?

On Sep 13, 11:32 pm, bingo bob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 14, 2008, 6:21am UTC](https://www.ruby-forum.com/t/basic-select-drop-down-returning-the-right-params/148481/8 "2008-09-14T06:21:04Z")

</div>

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](http://localhost:3000/enquiries/show/5)

If you’re using RESTful routes, that url should be:  
[http://localhost:3000/enquiries/5/show](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
