# Combo Select Filter Data

**URL:** <https://www.ruby-forum.com/t/combo-select-filter-data/147054>\
**Category:** Rails\
**Created:** [August 28, 2008, 12:36am UTC](https://www.ruby-forum.com/t/combo-select-filter-data/147054 "2008-08-28T00:36:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [August 28, 2008, 12:36am UTC](https://www.ruby-forum.com/t/combo-select-filter-data/147054/1 "2008-08-28T00:36:26Z")

</div>

Hi, this is my second post ( sorry for my language )

need yours helps with my problem.  
i need filter my model by an option in a Combo select

i thing, “i should be” with observe\_field and render partial, but i have  
a problem, when past to the second page, the application give me an  
error. about ID

thx for your helps!

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [August 28, 2008, 12:44am UTC](https://www.ruby-forum.com/t/combo-select-filter-data/147054/2 "2008-08-28T00:44:52Z")

</div>

David,

Could you post the code that you are using as well as the error message  
that it’s returning?

David navarrete David wrote:

> Hi, this is my second post ( sorry for my language )
> 
> need yours helps with my problem.  
> i need filter my model by an option in a Combo select
> 
> i thing, “i should be” with observe\_field and render partial, but i have  
> a problem, when past to the second page, the application give me an  
> error. about ID
> 
> thx for your helps!

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [August 28, 2008, 12:47am UTC](https://www.ruby-forum.com/t/combo-select-filter-data/147054/3 "2008-08-28T00:47:51Z")

</div>

\*\*\* controller \*\*  
def filtro  
if !params[:filtro][:campo].nil?  
tipo\_filtro = params[:filtro][:campo]  
@inmobiliaria = Inmobiliaria.find(params[:id])  
proyecto = @inmobiliaria.proyectos\_inmobiliarios.find(:all,  
:conditions =\> [‘tipo\_propiedad\_id = ?’,tipo\_filtro])  
end  
@proyectos = proyecto.paginate :page =\> params[:page], :per\_page =\>  
10  
@numero\_proyectos = proyecto.size  
render :partial =\> “resultado\_inmobiliaria”, :layout =\> false,  
:object =\> @proyectos  
end

* * *

\*\*\* show \*\*  
\<% form\_for ‘filtro’, :url =\> {:action =\> :filtro, :id =\> params[:id]}  
do |f| %\>  
\<%= f.select :campo,  
@tipos\_propiedades.collect {|p| [p.descripcion, p.id] },{  
:prompt =\> ‘Seleccione Filtro’}, {:onchange =\> “submit();”} %\>  
\<%= f.submit “asd”%\>

\<% end %\>

 \<%= render :action =\> "resultado\_inmobiliaria" %\>
\*\* show \*\*

thx

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [August 28, 2008, 12:48am UTC](https://www.ruby-forum.com/t/combo-select-filter-data/147054/4 "2008-08-28T00:48:34Z")

</div>

ups the error

You have a nil object when you didn’t expect it!  
You might have expected an instance of ActiveRecord::Base.  
The error occurred while evaluating nil.[]

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [August 28, 2008, 8:25am UTC](https://www.ruby-forum.com/t/combo-select-filter-data/147054/5 "2008-08-28T08:25:49Z")

</div>

try:

if params[:filtro] && !params[:filtro][:campo].nil?  
…

or

if (params[:filtro][:campo] rescue false)

if there’s no params[:filtro], the chained call to [:campo] will cause  
that error.

On Aug 27, 5:48 pm, David navarrete David \<rails-mailing-l…@andreas-
