# Need help with controller/show.html.erb

**URL:** <https://www.ruby-forum.com/t/need-help-with-controller-show-html-erb/165947>\
**Category:** Rails\
**Created:** [April 20, 2009, 9:29am UTC](https://www.ruby-forum.com/t/need-help-with-controller-show-html-erb/165947 "2009-04-20T09:29:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 20, 2009, 9:29am UTC](https://www.ruby-forum.com/t/need-help-with-controller-show-html-erb/165947/1 "2009-04-20T09:29:21Z")

</div>

Hello,

I am attempting to display data in the requseraccount form, from the  
divisions table.

For example: I have a division\_id field in requseraccount that works  
great. No issues getting this populated from my create form. The  
problem is that I don’t want to display the id when showing the form.  
I want to display the division\_name, which is in the division table.

Here is a copy of my code  
requseraccounts\_controller.rb and schema.rb: [http://dpaste.com/35716/](http://dpaste.com/35716/)  
requseraccoutns: show.html.erb: [http://dpaste.com/35717/](http://dpaste.com/35717/)  
SQL Query: [http://dpaste.com/35725/](http://dpaste.com/35725/)

I get the following error when I try the above code:

ActiveRecord::RecordNotFound in RequseraccountsController#show

Couldn’t find Division with ID=8

Which makes sense, since it is trying to do a query WHERE  
division\_id=8. I need the query to use requseaccount.divisions\_id  
(which is 2) and not requseraccount.id (which is 8).

Any advice would be much appreciated.

Michael

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 20, 2009, 12:41pm UTC](https://www.ruby-forum.com/t/need-help-with-controller-show-html-erb/165947/2 "2009-04-20T12:41:03Z")

</div>

Hi Michael

You have to specify the association between division and requseraccount  
models

In your models directory:

division.rb

class Division \< ActiveRecord::Base  
has\_many :requseraccount  
end

class Requseraccount \< ActiveRecord::Base  
belongs\_to :division  
end

And now you can do the following in your controller and view:

@req = Requseraccount.find(:all, :include =\> :division)  
@req.division.name # “division\_name”

You can read more about it at [http://guides.rubyonrails.org/](http://guides.rubyonrails.org/). And about  
associations in [Active Record Associations — Ruby on Rails Guides](http://guides.rubyonrails.org/association_basics.html)

Regards

Michael R wrote:

> Hello,
> 
> I am attempting to display data in the requseraccount form, from the  
> divisions table.
> 
> For example: I have a division\_id field in requseraccount that works  
> great. No issues getting this populated from my create form. The  
> problem is that I don’t want to display the id when showing the form.  
> I want to display the division\_name, which is in the division table.
> 
> Here is a copy of my code  
> requseraccounts\_controller.rb and schema.rb: [http://dpaste.com/35716/](http://dpaste.com/35716/)  
> requseraccoutns: show.html.erb: [http://dpaste.com/35717/](http://dpaste.com/35717/)  
> SQL Query: [http://dpaste.com/35725/](http://dpaste.com/35725/)
> 
> I get the following error when I try the above code:
> 
> ActiveRecord::RecordNotFound in RequseraccountsController#show
> 
> Couldn’t find Division with ID=8
> 
> Which makes sense, since it is trying to do a query WHERE  
> division\_id=8. I need the query to use requseaccount.divisions\_id  
> (which is 2) and not requseraccount.id (which is 8).
> 
> Any advice would be much appreciated.
> 
> Michael
