# Return only some resources from 2 tables

**URL:** <https://www.ruby-forum.com/t/return-only-some-resources-from-2-tables/162594>\
**Category:** Rails\
**Created:** [March 11, 2009, 6:12pm UTC](https://www.ruby-forum.com/t/return-only-some-resources-from-2-tables/162594 "2009-03-11T18:12:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 11, 2009, 6:12pm UTC](https://www.ruby-forum.com/t/return-only-some-resources-from-2-tables/162594/1 "2009-03-11T18:12:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 11, 2009, 7:43pm UTC](https://www.ruby-forum.com/t/return-only-some-resources-from-2-tables/162594/2 "2009-03-11T19:43:17Z")

</div>

On Wed, 11 Mar 2009 18:12:12 +0100  
Heinz S. [removed\_email\_address@domain.invalid](mailto: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](http://starrhorne.com)  
Check out my Helpdesk RailsKit: [http://railskits.com/helpdesk/](http://railskits.com/helpdesk/)

---

<div class="post-metadata">

**Author:** ![cojones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9f8e36/32.png) [@cojones](https://www.ruby-forum.com/u/cojones)\
**Post date:** [March 12, 2009, 9:22am UTC](https://www.ruby-forum.com/t/return-only-some-resources-from-2-tables/162594/3 "2009-03-12T09:22:44Z")

</div>

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
