Forum: Ruby on Rails Controller / Model confusion

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A147f89794afd36b55bd9d5ed5c7933b?d=identicon&s=25 Matt Lee (Guest)
on 2006-01-19 17:47
I have created a product, with two controllers and two models, one for
categories and one for articles. In my models directory, I have
article.rb and articles.rb and seem to have code that relies on both of

I am unable to get any validation working because of this (whichever
model I put the code in, it doesn't load it)

Should I just rip it all apart and start again?
69b2ef4bce76b5b27c94e898976dc6d8?d=identicon&s=25 matthew clark (Guest)
on 2006-01-19 22:05
(Received via mailing list)
the name of the controller file should be article.rb, and the class

Write some tests, see what is depending on the other class, and

28c237c0c414b644082bfcde4e42b309?d=identicon&s=25 John Leach (Guest)
on 2006-01-19 22:08
(Received via mailing list)

not sure what you've done to get what you've got, but the destroy script
will certainly help you clean up properly (i.e: it removes the tests and
helpers and stuff)


ruby script/destroy controller article

p.s: we off for a curry tomorrow night?  Omar's in Bradford yeah? ;)
p.p.s: anyone in Bradford, UK is welcome to join us too :)
A147f89794afd36b55bd9d5ed5c7933b?d=identicon&s=25 Matt Lee (Guest)
on 2006-01-19 23:36
Now getting:-

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.inject

The offending snippet of code is:-

<select id="article_category_id" name="article[category_id]">
    	<%= options_from_collection_for_select categories, "id",
"category", article.category_id %>

My form itself is in a partial, which I am rendering with:-

  <%= render :partial => 'form', :locals => {:article => @article,
:categories => @categories} %>

34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2006-01-20 10:17
Can't really see what's going on there, but what you SHOULD have is:

you should have two controllers called categories.rb and articles.rb in
the controllers folder.

And your models folder should contain the singular of these, so
category.rb and article.rb.

Other than that, your partial seems correct. You sure @categories and
@article are set correctly in your controller? They appear to be nil.
Have a look at the Sql in your logfiles and run it on your database to
make sure it returns the data you're expecting.

Is the name of your field that holds your category name called category?

Hope any of this helps you find the problem.

This topic is locked and can not be replied to.