# Need a second set of eyes to help me

**URL:** <https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427>\
**Category:** Rails\
**Created:** [April 8, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427 "2007-04-08T23:00:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 8, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427/1 "2007-04-08T23:00:25Z")

</div>

I think I am going blind, because I cannot find what is wrong with the  
following. The bad thing is that I had it working, made couple of  
changes, reverted back to the original, now it doesn’t work.

I have been trying to figure out why this isn’t working way too long,  
to the point my vision is blurring.

 \<% form\_for :categories, :url =\> {:action =\> "show\_tasks"} do |form| %\> Select Category: \<%= form.collection\_select :name, @categories, :id, :name %\> \<%= submit\_tag "View" %\> \<% end %\>

here is the error message

NoMethodError in Mytasks#index  
Showing app/views/mytasks/index.rhtml where line #10 raised:  
undefined method `name’ for #Array:0xb7611edc

Extracted source (around line #10):

7:

  
8: \<% form\_for :categories, :url =\> {:action =\> “show\_tasks”} do |  
form| %\>  
9: Select Category:  
10: \<%= form.collection\_select :name, @categories, :id, :name %\>  
11: \<%= submit\_tag “View” %\>  
12: \<% end %\>  
13: 

Thanks for the help

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 8, 2007, 11:12pm UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427/2 "2007-04-08T23:12:25Z")

</div>

On 8-Apr-07, at 4:58 PM, chris wrote:

> %\>  
> undefined method `name’ for #Array:0xb7611edc  
> 13:   
> Chris, @categories is your problem.

collection\_select is iterating through @categories looking for  
category.name.

Take a look at your controller where you’re populating @categories.

Cheers,  
Jodi  
General Partner  
The nNovation Group inc.  
www.nnovation.ca/blog

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 9, 2007, 12:05am UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427/3 "2007-04-09T00:05:33Z")

</div>

Sorry, I should’ve mentioned that there has been no changes to the  
controller since I had it working.  
Here is the index method from the controller

def index  
@categories = Category.find(:all)  
@tasks = []  
end

But the error is in regards to to the \*select control. If I remove  
line 10 from the index.rhtml file it renders to the browser without  
any errors.

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 9, 2007, 1:24am UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427/4 "2007-04-09T01:24:37Z")

</div>

Hi Chris, you should be able to do the following:

\<%= form.collection\_select ‘task’, ‘category\_id’, @categories, ‘id’,  
‘\<some\_category\_attribute\>’ %\>

This invocation will generate a select tag name=“task[category\_id]” with  
options of form category.\<some\_category\_attribute\>. The  
option with category.id == user.category\_id will be selected.

Now, I’m guessing the following from you previous e-mail:

task belongs\_to category  
category has\_many tasks

Thus, I’m seeing the following relationship:

class Task \< ActiveRecord::Base  
belongs\_to :category  
end

class Category \< ActiveRecord::Base  
has\_many :tasks  
end

Please note that Task model contains the foreign key, ‘category\_id’,  
because it has the belongs\_to declaration.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 9, 2007, 2:29am UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427/5 "2007-04-09T02:29:40Z")

</div>

maybe this will help. I totally removed the linkage to the categories  
and tried to hard code some values, with some random names

 \<% form\_for :categories, :url =\> {:action =\> "show\_tasks"} do |form| %\> Select Category: \<%= form.select "some\_names", %w{Chris, Andy, Wally} %\> \<%= submit\_tag "View" %\> \<% end %\>

# Here is the error message

NoMethodError in Mytasks#index  
Showing app/views/mytasks/index.rhtml where line #10 raised:  
undefined method `some\_names’ for #Array:0xb757f654

Extracted source (around line #10):

7:

  
8: \<% form\_for :categories, :url =\> {:action =\> “show\_tasks”} do |  
form| %\>  
9: Select Category:  
10: \<%= form.select “some\_names”, %w{Chris, Andy, Wally} %\>  
11: \<%= submit\_tag “View” %\>  
12: \<% end %\>  
13:

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 9, 2007, 2:19am UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427/6 "2007-04-09T02:19:39Z")

</div>

Since I am just playing around with things I am constantly re-  
formatting how things are arranged on the screen. How this is  
supposed to work, is that at the top of the screen there is a select  
list containing the categories, that combined within the button beside  
it, allows the user to easily view the todo’s for each of the  
categories.

So the select control that I am having problems with isn’t yet, at the  
time of the problem, related to the tasks just yet. I want to fill  
the select control with all the categories that exist in the database.

Thanks for the help, I really appreciate it.

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 9, 2007, 4:11am UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427/7 "2007-04-09T04:11:46Z")

</div>

Hi, you should be able to do the following:

1. Define this in the relevant model.

category\_type = [  
[“Chris”, “1”]  
[“Andy”, “2”]  
[“Wally”, “3”]  
]

1. Add this code to the relevant view.

\<%= form.select :some\_names, \<class\_name\>::category\_type %\>

Note: \<class\_name\> := The name of your model class. For example,

```
     Category

```

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 9, 2007, 4:12am UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427/8 "2007-04-09T04:12:46Z")

</div>

Hi, here’s the corrected version:

category\_type = [  
[“Chris”, “1”],  
[“Andy”, “2”],  
[“Wally”, “3”]  
]

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 9, 2007, 5:20am UTC](https://www.ruby-forum.com/t/need-a-second-set-of-eyes-to-help-me/91427/9 "2007-04-09T05:20:51Z")

</div>

Here is the updated snippet from the rhtml file  
++++++++++++++++++

 \<% form\_for :categories, :url =\> {:action =\> "show\_tasks"} do |form| %\> Select Category: \<%= form.select :brothers, Category::BROTHERS %\> \<%= submit\_tag "View" %\> \<% end %\>

Here is the addition of the BROTHERS array in the category model  
++++++++++++++++++  
class Category \< ActiveRecord::Base  
has\_many :tasks

BROTHERS = [  
[“1”, “Chris”],  
[“2”, “Tim”],  
[“3”, “Tom”]  
]  
end

And here is the error ☹  
++++++++++++++++++++  
NoMethodError in Mytasks#index

Showing app/views/mytasks/index.rhtml where line #10 raised:

undefined method `brothers’ for #Array:0xb7739c4c

Extracted source (around line #10):

7:

  
8: \<% form\_for :categories, :url =\> {:action =\> “show\_tasks”} do |  
form| %\>  
9: Select Category:  
10: \<%= form.select :brothers, Category::BROTHERS %\>  
11: \<%= submit\_tag “View” %\>  
12: \<% end %\>  
13:
