need a second set of eyes to help me

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.

<div style="border:3px solid #999">   <% form_for :categories, :url => {:action => "show_tasks"} do |form| %>   Select Category:   <%= form.collection_select :name, @categories, :id, :name %>   <%= submit_tag "View" %>   <% end %> </div>

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: <div style="border:3px solid #999"> 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: </div>

Thanks for the help

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

on-innovation.gif

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.

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 <option value="category.id">category.<some_category_attribute></option>. 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

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.

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

<div style="border:3px solid #999">   <% form_for :categories, :url => {:action => "show_tasks"} do |form| %>   Select Category:   <%= form.select "some_names", %w{Chris, Andy, Wally} %>   <%= submit_tag "View" %>   <% end %> </div>

Here is the error message

Hi, you should be able to do the following:

1) Define this in the relevant model.

category_type = [ [ "Chris", "1" ] [ "Andy", "2" ] [ "Wally", "3" ] ]

2) 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

Hi, here's the corrected version:

category_type = [ [ "Chris", "1" ], [ "Andy", "2" ], [ "Wally", "3" ] ]

Here is the updated snippet from the rhtml file