Forum: Ruby on Rails Return only some resources from 2 tables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Heinz S. (Guest)
on 2009-03-11 19:12
Hello,

I'm having trouble selecting only some specific resources from 2 tables.
That's my code:
categories = %w{cat1 cat2 cat3}
categories.each { |category|
  cat = CharacterAttributeCategory.find_by_name category
  @character_attribute_types +=
CharacterAttributeType.find_all_by_character_attribute_category_id
cat.id
}

I tried << before but that doesn't work as well. I get following error:
NoMethodError in CharactersController#new

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.+

Any hints?
Starr H. (Guest)
on 2009-03-11 20:43
(Received via mailing list)
On Wed, 11 Mar 2009 18:12:12 +0100
Heinz S. <removed_email_address@domain.invalid> wrote:

> I'm having trouble selecting only some specific resources from 2 tables.
> That's my code:
> categories = %w{cat1 cat2 cat3}
> categories.each { |category|
>   cat = CharacterAttributeCategory.find_by_name category
>   @character_attribute_types +=
> CharacterAttributeType.find_all_by_character_attribute_category_id
> cat.id
> }

Do you mean this?

@character_attribute_types = []
@character_attribute_types <<
CharacterAttributeType.find_all_by_character_attribute_category_id

SH

--
Starr H.
My blog: http://starrhorne.com
Check out my Helpdesk RailsKit: http://railskits.com/helpdesk/
Heinz S. (Guest)
on 2009-03-12 10:22
Hey,

I just tried that, didn't help. Here's the error:
characters_controller.rb:21: syntax error, unexpected tIDENTIFIER,
expecting '}' @character_attribute_types <<
CharacterAttributeType.find_all_by_character_attribute_type_category_id
cat.id
This topic is locked and can not be replied to.