# Problem with my show page

**URL:** <https://www.ruby-forum.com/t/problem-with-my-show-page/164612>\
**Category:** Rails\
**Created:** [April 3, 2009, 3:32am UTC](https://www.ruby-forum.com/t/problem-with-my-show-page/164612 "2009-04-03T03:32:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rikki123s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/df788c/32.png) [@rikki123s](https://www.ruby-forum.com/u/rikki123s)\
**Post date:** [April 3, 2009, 3:32am UTC](https://www.ruby-forum.com/t/problem-with-my-show-page/164612/1 "2009-04-03T03:32:43Z")

</div>

Ok I have now got my papers to be able to have an author be selected for  
them from a drop down box generated in the new paper page  
‘papers/new.html.erb’, which was fixed in an earlier post.

Now I have a problem on the other side of the site, I now want to  
display a table in the authors show page ‘authors/show.html.erb’, that  
displays all the papers made by the specific author shown in the authors  
show page.

How I plan to do this is by getting the authors controller to only pick  
from the papers table where the papers.author field = the authors.name  
field (both fields being the author name).

So far I have the table set out in the authors/show.html.erb page like  
this:

Papers owned by the Author

\<% for paper in @papers %\>

  
  
  
\<% end %\>

| Paper |
| \<%=h paper.title %\> |

And so far the show method for my author controller is displayed as so:

def show  
@author = Author.find(params[:id])  
@papers = Paper.find(:all)

```
respond_to do |format|
  format.html # show.html.erb
  format.xml { render :xml => @author }
  format.xml { render :xml => @papers }
end

```

end

Obviously all this is going to do is show all the papers in the papers  
table, rather than the ones whos author = the author name in the authors  
table.

Could anyone help me with this? I beleive that the change needs to be  
made in the ‘@papers = Paper.find(:all)’ line in the controller, i just  
do not know what to replace this line with.

Thanks for any replies.

---

<div class="post-metadata">

**Author:** ![rikki123s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/df788c/32.png) [@rikki123s](https://www.ruby-forum.com/u/rikki123s)\
**Post date:** [April 3, 2009, 3:46am UTC](https://www.ruby-forum.com/t/problem-with-my-show-page/164612/2 "2009-04-03T03:46:23Z")

</div>

Hi Rik,

On Fri, 2009-04-03 at 03:32 +0200, Rik Stott wrote:

> I beleive that the change needs to be made in the  
> ‘@papers = Paper.find(:all)’ line in the controller,  
> i just do not know what to replace this line with.

I didn’t see your other posts so I’m not sure what your associations  
look like but assuming it’s:

Paper -\> belongs\_to :author

@papers = Paper.find\_all\_by\_author\_id(params[:id]

and then you can get rid of the find on Author.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![rikki123s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/df788c/32.png) [@rikki123s](https://www.ruby-forum.com/u/rikki123s)\
**Post date:** [April 3, 2009, 3:59am UTC](https://www.ruby-forum.com/t/problem-with-my-show-page/164612/3 "2009-04-03T03:59:21Z")

</div>

Hey Bill,

I tried that, but it came out with an error saying:

“undefined method `find\_all\_by\_author\_id’ for #Class:0x7380e94”

I cannot delete the find on the author because that is required for a  
different table on the page.

I then realised it should have been ‘find\_all\_by\_author’, because the  
field in the papers page is called ‘author’, not author\_id.

the problem I now have is that the page will display, with the table,  
but there is no records being shown.

the author field in the authors table is named ‘name’, should i change  
this to ‘author’ also?

thanks for your help

bill walton wrote:

> Hi Rik,
> 
> On Fri, 2009-04-03 at 03:32 +0200, Rik Stott wrote:
> 
> > I beleive that the change needs to be made in the  
> > ‘@papers = Paper.find(:all)’ line in the controller,  
> > i just do not know what to replace this line with.
> 
> I didn’t see your other posts so I’m not sure what your associations  
> look like but assuming it’s:
> 
> Paper -\> belongs\_to :author
> 
> @papers = Paper.find\_all\_by\_author\_id(params[:id]
> 
> and then you can get rid of the find on Author.
> 
> HTH,  
> Bill

---

<div class="post-metadata">

**Author:** ![rikki123s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/df788c/32.png) [@rikki123s](https://www.ruby-forum.com/u/rikki123s)\
**Post date:** [April 3, 2009, 4:42am UTC](https://www.ruby-forum.com/t/problem-with-my-show-page/164612/4 "2009-04-03T04:42:00Z")

</div>

I’ve sussed it.

by now I have changed the field in paper from :author, to :name. I’ve  
done a lot of work and can’t be bothered back tracking everything for  
just the sake of changing it back. it works like this anyway so it  
doesn’t matter.

once I had changed the name of the authors field on the papers table to  
:name, the code I typed into the controller to replace the line was:

“@papers = Paper.find\_all\_by\_name(params = @author[:name])”

this works 🙂 thanks for your aid Bill

---

<div class="post-metadata">

**Author:** ![rikki123s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/df788c/32.png) [@rikki123s](https://www.ruby-forum.com/u/rikki123s)\
**Post date:** [April 3, 2009, 5:41am UTC](https://www.ruby-forum.com/t/problem-with-my-show-page/164612/5 "2009-04-03T05:41:48Z")

</div>

Hi Rik,

On Fri, 2009-04-03 at 04:42 +0200, Rik Stott wrote:

> this works 🙂 thanks for your aid Bill

You’re welcome. Glad you got it working.

Best regards,  
Bill
