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: <div align="center">Papers owned by the Author</div> <table border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#000033" bgcolor="#8A75FF"> <tr> <td bgcolor="#CAC4FF">Paper</td> </tr> <% for paper in @papers %> <tr> <td><%=h paper.title %></td> </tr> <% end %> </table> 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Rik, On Fri, 2009-04-03 at 04:42 +0200, Rik Stott wrote:> this works :) thanks for your aid BillYou''re welcome. Glad you got it working. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---