# Collection\_select problem

**URL:** <https://www.ruby-forum.com/t/collection-select-problem/154245>\
**Category:** Rails\
**Created:** [November 26, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/collection-select-problem/154245 "2008-11-26T18:04:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 26, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/collection-select-problem/154245/1 "2008-11-26T18:04:12Z")

</div>

Hi, first and foremost sorry if my english is not the best.

I want to choose between somo products in a view.

I have tickets and i wanna add tickets\_products.

1)ruby script/generate scaffold ticket\_product name:string  
2) rake db: migrate  
3) Models-\> ticket belongs to ticketproducts and ticketproducts has  
many tickets.  
4) I use Sqlite Manager (firefox pluggin) and I added two ticket  
products with this soft in tickets\_products table.

5)I wrote this in new.html.erb (ticket view):

\<% form\_for(@ticket) do |f| %\>

| \<%= \_('Product') %\> | \<%= \_('Breakdown') %\> | \<%= \_('State') %\> |
| --- | --- | --- |
| \<%= f.collection\_select :ticket\_product\_id, @ticket\_products, :id, :name, :prompt =\> \_("Select product") %\> | \<%= f.collection\_select :ticket\_breakdown\_id, @ticket\_breakdowns, :id, :title, :prompt =\> \_("Select breakdown") %\> | \<%= f.collection\_select :ticket\_state\_id, @ticket\_states, :id, :title, :prompt =\> \_("Select state") %\> |

The error is:

NoMethodError in Tickets#new

Showing tickets/new.html.erb where line #14 raised:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.map

Extracted source (around line #14):

11:

\<%= ‘Estado del producto’ %\>  
12:   
13:   
14: \<%= f.collection\_select :ticket\_product\_id,  
@ticket\_products, :id, :name, :prompt=\> “Seleccione producto” %\>  
15: \<%= f.text\_field :ticket\_breakdown\_id %\>   
16: \<
* * *

i donÂ´t ubderstand it, because I have two elements in ticket\_products

Somebody can help me please??

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 26, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/collection-select-problem/154245/2 "2008-11-26T18:06:43Z")

</div>

Sorry,donÂ´t take care this code:

\<%= f.collection\_select :ticket\_breakdown\_id, \> @ticket\_breakdowns, :id, :title, :prompt =\> \_("Select breakdown") %\> \> \> \<%= f.collection\_select :ticket\_state\_id, @ticket\_states, :id, \> :title, :prompt =\> \_("Select state") %\> \> 

It will be implemented soon as possible but not yet.

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 26, 2008, 7:42pm UTC](https://www.ruby-forum.com/t/collection-select-problem/154245/3 "2008-11-26T19:42:52Z")

</div>

Solved…it is normal…☹

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.map

tickets\_controller.rb  
def new  
@ticket = Ticket.new  
@ticket\_products= TicketProduct.find(:all, :order =\>‘name’) ## this  
line finds the tickets product!!!

```
respond_to do |format|
  format.html # new.html.erb
  format.xml { render :xml => @ticket }
end

```

end

Thanks a lot!!!
