# Updating a model from a checkbox (noob question)

**URL:** <https://www.ruby-forum.com/t/updating-a-model-from-a-checkbox-noob-question/99061>\
**Category:** Rails\
**Created:** [July 20, 2006, 1:49am UTC](https://www.ruby-forum.com/t/updating-a-model-from-a-checkbox-noob-question/99061 "2006-07-20T01:49:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roytruelove](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ab097/32.png) [@roytruelove](https://www.ruby-forum.com/u/roytruelove)\
**Post date:** [July 20, 2006, 1:49am UTC](https://www.ruby-forum.com/t/updating-a-model-from-a-checkbox-noob-question/99061/1 "2006-07-20T01:49:18Z")

</div>

Hello everyone,

I’m trying to wire a combobox in a view to update the database. When I  
select something in the combobox and press ‘update’ it goes through  
fine, except it places the default value for the field of the combobox.  
Any suggestions?

Here’s the model:

class TestResult \< ActiveRecord::Base  
has\_one :status\_index  
has\_one :test\_type  
has\_one :product\_area  
validates\_presence\_of :statusindex\_id, :testtype\_id, :productarea\_id,  
:name  
end

This generates the combobox (inside a view partial):

\<%= select(“test\_type”, “id”, TestType.find\_all.collect {|tt| [tt.name,  
tt.id] }, { :include\_blank =\> false}) %\>

Here’s the command in the controller’s ‘update’ method:

@test\_result.update\_attributes(params[:test\_result])

Thanks very much,  
Roy T.

---

<div class="post-metadata">

**Author:** ![roytruelove](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ab097/32.png) [@roytruelove](https://www.ruby-forum.com/u/roytruelove)\
**Post date:** [July 20, 2006, 2:56am UTC](https://www.ruby-forum.com/t/updating-a-model-from-a-checkbox-noob-question/99061/2 "2006-07-20T02:56:48Z")

</div>

Updating a model from a checkbox (noob question)Hi Roy,

Roy T. wrote:

> \<%= select(“test\_type”, “id”, TestType.find\_all.collect  
> {|tt| [tt.name, tt.id] }, { :include\_blank =\> false}) %\>

> Here’s the command in the controller’s ‘update’ method:  
> @test\_result.update\_attributes(params[:test\_result])

I could be wrong, but based on what you’ve shown us, I’m pretty sure the  
result of your select is going to come back to the controller in  
params[:test\_type][:id], not in params[:test\_result]. But I could  
definitely be wrong because I don’t have any experience with  
using.find’s in  
my views.

You might want to use a ‘dummy’ view with \<%= params.inspect %\> to check  
to  
see exactly what _is_ coming back.

hth,  
Bill
