# Select in list.rhtml

**URL:** <https://www.ruby-forum.com/t/select-in-list-rhtml/144027>\
**Category:** Rails\
**Created:** [July 24, 2008, 7:13pm UTC](https://www.ruby-forum.com/t/select-in-list-rhtml/144027 "2008-07-24T19:13:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [July 24, 2008, 7:13pm UTC](https://www.ruby-forum.com/t/select-in-list-rhtml/144027/1 "2008-07-24T19:13:47Z")

</div>

i am new to ruby on rails, and this might be a simple one but i have  
no idea what to do.  
i need to put a select (\_tag or whatever) into a list.rhtml and get  
the selected value from this. Putting the select to the view works  
fine. The displayed options are ok too, but i don’t know how to get  
the selected option. What i have so far:

\<% for calendar in @calendars %\>

\<%= link\_to "#{calendar.person.account}", { :controller =\> 'person', :action =\> 'list', :person\_id =\> calendar.person.id } %\> \<%= link\_to "#{calendar.calendar\_state.name}", { :controller =\> 'calendar', :action =\> 'list', :calendar\_state\_id =\> calendar.calendar\_state } %\> \<%= select 'calendar', 'project\_has\_person\_id', ProjectHasPerson.find(:all, :conditions =\> ["person\_id = ?", calendar.person.id]).collect{ |p| [p.person.account + "@" + p.project.name, p.id]} %\>

\<% for column in Calendar.content\_columns %\>

\<%=h calendar.send(column.name) %\>  
\<% end %\> \<%= link\_to 'assign', :action =\> 'assign', :id =\> calendar %\> \<% end %\>

The calendar-entry has a column called project\_has\_person\_id, but  
whenever i try to access the parameter in the controller with  
params[:project\_has\_person\_id] the value will be nil.

Any help is appreciated!

Thanks

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [July 24, 2008, 8:41pm UTC](https://www.ruby-forum.com/t/select-in-list-rhtml/144027/2 "2008-07-24T20:41:12Z")

</div>

On Thu, Jul 24, 2008 at 8:04 AM, marco [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= link\_to "#{calendar.person.account}", { :controller =\> \<% for column in Calendar.content\_columns %\> \<%=h calendar.send(column.name) %\> \<% end %\> \<%= link\_to 'assign', :action =\> 'assign', :id =\> calendar %\> \<% end %\>
> 
> The calendar-entry has a column called project\_has\_person\_id, but  
> whenever i try to access the parameter in the controller with  
> params[:project\_has\_person\_id] the value will be nil.

I suspect that the value is in  
params[:calendar][:project\_has\_person\_id].

The development log will show you all of the values of the params  
object.

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [July 28, 2008, 12:53pm UTC](https://www.ruby-forum.com/t/select-in-list-rhtml/144027/3 "2008-07-28T12:53:47Z")

</div>

thank you for your reply.  
i have tried your solution, but it didn’t work either.  
is there really no way to pass a selected value coming from a  
selection to a controller?

marco

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [July 24, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/select-in-list-rhtml/144027/4 "2008-07-24T19:30:12Z")

</div>

Citando marco [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> \<%= link\_to "#{calendar.person.account}", { :controller =\> \<% for column in Calendar.content\_columns %\>
> 
> Any help is appreciated!

You might be interessed in this article:  
[http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model](http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model)

Sorry for my poor English.

HTH,

Davi V.

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [July 28, 2008, 1:07pm UTC](https://www.ruby-forum.com/t/select-in-list-rhtml/144027/5 "2008-07-28T13:07:51Z")

</div>

Hi macro,

Try to place your select statement inside a form tag instead of  
link\_to, only then it submits the selection to the controller.  
Then you need to access the selection by params[:calendar]  
[:project\_has\_person\_id] as stated by Christopher.

Thanks,  
Kiran.  
[http://kiran.gnufied.org](http://kiran.gnufied.org)

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [July 29, 2008, 12:39pm UTC](https://www.ruby-forum.com/t/select-in-list-rhtml/144027/6 "2008-07-29T12:39:55Z")

</div>

Thanks a lot Kiran!  
That did exactly what i want.

marco
